Skip to content

Commit

Permalink
Merge pull request alibaba#4913 from chenhaoyus/master
Browse files Browse the repository at this point in the history
Add oscar parser support
  • Loading branch information
wenshao authored Sep 5, 2022
2 parents abe8342 + 64230b8 commit eb781b6
Show file tree
Hide file tree
Showing 29 changed files with 5,690 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/alibaba/druid/sql/SQLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleToMySqlOutputVisitor;
import com.alibaba.druid.sql.dialect.oscar.visitor.OscarOutputVisitor;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor;
import com.alibaba.druid.sql.dialect.presto.visitor.PrestoOutputVisitor;
Expand Down Expand Up @@ -519,6 +520,8 @@ public static SQLASTOutputVisitor createFormatOutputVisitor(Appendable out,
return new PrestoOutputVisitor(out);
case clickhouse:
return new ClickhouseOutputVisitor(out);
case oscar:
return new OscarOutputVisitor(out);
default:
return new SQLASTOutputVisitor(out, dbType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.oscar.ast;

import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.dialect.oscar.visitor.OscarASTVisitor;

public interface OscarObject extends SQLObject {
void accept0(OscarASTVisitor visitor);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.oscar.ast;

import com.alibaba.druid.sql.ast.SQLObjectImpl;
import com.alibaba.druid.sql.dialect.oscar.visitor.OscarASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

public abstract class OscarObjectImpl extends SQLObjectImpl implements OscarObject {
public OscarObjectImpl() {
}

@Override
protected void accept0(SQLASTVisitor visitor) {
this.accept0((OscarASTVisitor) visitor);
}

public abstract void accept0(OscarASTVisitor visitor);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.oscar.ast;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
import com.alibaba.druid.sql.dialect.oscar.visitor.OscarASTVisitor;

public class OscarTop extends OscarObjectImpl {
private SQLExpr expr;
private boolean percent;
private boolean withTies;

public OscarTop() {
}

@Override
public void accept0(OscarASTVisitor visitor) {
}

public OscarTop(SQLExpr expr) {
this.setExpr(expr);
}

public SQLExpr getExpr() {
return expr;
}

public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}

public void setExpr(int expr) {
this.setExpr(new SQLIntegerExpr(expr));
}

public boolean isPercent() {
return percent;
}

public void setPercent(boolean percent) {
this.percent = percent;
}

public boolean isWithTies() {
return withTies;
}

public void setWithTies(boolean withTies) {
this.withTies = withTies;
}

public OscarTop clone() {
OscarTop x = new OscarTop();
if (expr != null) {
x.setExpr(expr.clone());
}
x.percent = percent;
x.withTies = withTies;
return x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.oscar.ast.expr;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.dialect.oscar.ast.OscarObject;

public interface OscarExpr extends SQLExpr, OscarObject {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.oscar.ast.stmt;

import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.statement.SQLAlterStatement;
import com.alibaba.druid.sql.dialect.oscar.visitor.OscarASTVisitor;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

public class OscarAlterSchemaStatement extends SQLStatementImpl implements OscarStatement, SQLAlterStatement {
private SQLIdentifierExpr schemaName;
private SQLIdentifierExpr newName;
private SQLIdentifierExpr newOwner;

public SQLIdentifierExpr getSchemaName() {
return schemaName;
}

public void setSchemaName(SQLIdentifierExpr schemaName) {
this.schemaName = schemaName;
}

protected void accept0(SQLASTVisitor visitor) {
accept0((PGASTVisitor) visitor);
}

public SQLIdentifierExpr getNewName() {
return newName;
}

public void setNewName(SQLIdentifierExpr newName) {
this.newName = newName;
}

public SQLIdentifierExpr getNewOwner() {
return newOwner;
}

public void setNewOwner(SQLIdentifierExpr newOwner) {
this.newOwner = newOwner;
}

@Override
public void accept0(OscarASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.schemaName);
acceptChild(visitor, this.newName);
acceptChild(visitor, this.newOwner);
}
visitor.endVisit(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.oscar.ast.stmt;

public class OscarAlterTableAlterColumnSetNotNull {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.alibaba.druid.sql.dialect.oscar.ast.stmt;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.dialect.oscar.visitor.OscarASTVisitor;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

public class OscarConnectToStatement extends SQLStatementImpl implements OscarStatement {
private SQLName target;

public OscarConnectToStatement() {
super(DbType.oscar);
}

protected void accept0(SQLASTVisitor visitor) {
this.accept0((PGASTVisitor) visitor);
}

@Override
public void accept0(OscarASTVisitor v) {
if (v.visit(this)) {
acceptChild(v, target);
}
v.endVisit(this);
}

public SQLName getTarget() {
return target;
}

public void setTarget(SQLName x) {
if (x != null) {
x.setParent(this);
}
this.target = x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.oscar.ast.stmt;

import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.statement.SQLCreateStatement;
import com.alibaba.druid.sql.dialect.oscar.visitor.OscarASTVisitor;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

public class OscarCreateSchemaStatement extends SQLStatementImpl implements OscarStatement, SQLCreateStatement {
private SQLIdentifierExpr schemaName;
private SQLIdentifierExpr userName;
private boolean ifNotExists;
private boolean authorization;

public SQLIdentifierExpr getSchemaName() {
return schemaName;
}

public void setSchemaName(SQLIdentifierExpr schemaName) {
this.schemaName = schemaName;
}

public SQLIdentifierExpr getUserName() {
return userName;
}

public void setUserName(SQLIdentifierExpr userName) {
this.userName = userName;
}

public boolean isIfNotExists() {
return ifNotExists;
}

public void setIfNotExists(boolean ifNotExists) {
this.ifNotExists = ifNotExists;
}

public boolean isAuthorization() {
return authorization;
}

public void setAuthorization(boolean authorization) {
this.authorization = authorization;
}

protected void accept0(SQLASTVisitor visitor) {
accept0((PGASTVisitor) visitor);
}

@Override
public void accept0(OscarASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.schemaName);
acceptChild(visitor, this.userName);
}
visitor.endVisit(this);
}
}
Loading

0 comments on commit eb781b6

Please sign in to comment.