mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.druid.sql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.FastsqlException;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -27,6 +28,9 @@ import java.util.List;
|
||||
public final class SQLAllColumnExpr extends SQLExprImpl {
|
||||
private transient SQLTableSource resolvedTableSource;
|
||||
|
||||
private SQLExpr owner;
|
||||
private List<SQLExpr> except;
|
||||
|
||||
public SQLAllColumnExpr() {
|
||||
}
|
||||
|
||||
@@ -38,6 +42,25 @@ public final class SQLAllColumnExpr extends SQLExprImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public SQLExpr getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.owner = x;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getExcept() {
|
||||
return except;
|
||||
}
|
||||
|
||||
public void setExcept(List<SQLExpr> except) {
|
||||
this.except = except;
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
|
||||
+6
-1
@@ -20,7 +20,7 @@ import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterFunctionStatement extends SQLStatementImpl {
|
||||
public class SQLAlterFunctionStatement extends SQLStatementImpl implements SQLAlterStatement {
|
||||
private SQLName name;
|
||||
|
||||
private boolean debug;
|
||||
@@ -105,4 +105,9 @@ public class SQLAlterFunctionStatement extends SQLStatementImpl {
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.FUNCTION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,4 +161,9 @@ public class SQLAlterIndexStatement extends SQLStatementImpl implements SQLAlter
|
||||
}
|
||||
this.dbPartitionBy = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.INDEX;
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -175,4 +175,9 @@ public class SQLAlterMaterializedViewStatement extends SQLStatementImpl implemen
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.MATERIALIZED_VIEW;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,4 +98,9 @@ public class SQLAlterProcedureStatement extends SQLStatementImpl implements SQLA
|
||||
}
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.PROCEDURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,4 +224,9 @@ public class SQLAlterSequenceStatement extends SQLStatementImpl implements SQLAl
|
||||
}
|
||||
this.restartWith = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.SEQUENCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
public interface SQLAlterStatement extends SQLStatement {
|
||||
public interface SQLAlterStatement extends SQLDDLStatement {
|
||||
default DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLAlterTableArchive extends SQLObjectImpl implements SQLAlterTableItem {
|
||||
private final List<SQLAssignItem> partition = new ArrayList<SQLAssignItem>(4);
|
||||
|
||||
public List<SQLAssignItem> getPartition() {
|
||||
return partition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, partition);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -283,4 +283,9 @@ public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
public void setNotClustered(boolean notClustered) {
|
||||
this.notClustered = notClustered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,4 +278,9 @@ public class SQLAlterViewStatement extends SQLStatementImpl implements SQLCreate
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.VIEW;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -269,5 +269,8 @@ public class SQLCreateDatabaseStatement extends SQLStatementImpl implements SQLC
|
||||
this.physical = physical;
|
||||
}
|
||||
|
||||
// public static class StoredAs
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.DATABASE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,4 +326,9 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLCrea
|
||||
public void setIfNotExists(boolean ifNotExists) {
|
||||
this.ifNotExists = ifNotExists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.INDEX;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,4 +68,8 @@ public class SQLCreateRoleStatement extends SQLStatementImpl implements SQLCreat
|
||||
this.ifNotExists = ifNotExists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.ROLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,4 +257,9 @@ public class SQLCreateSequenceStatement extends SQLStatementImpl implements SQLC
|
||||
}
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.SEQUENCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,5 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
|
||||
public interface SQLCreateStatement extends SQLDDLStatement {
|
||||
default SQLName getName() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1566,4 +1566,8 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
}
|
||||
this.engine = x;
|
||||
}
|
||||
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,11 @@ public class SQLCreateTriggerStatement extends SQLStatementImpl implements SQLCr
|
||||
this.definer = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.TRIGGER;
|
||||
}
|
||||
|
||||
public static enum TriggerType {
|
||||
BEFORE, AFTER, INSTEAD_OF
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCreateUserStatement extends SQLStatementImpl {
|
||||
public class SQLCreateUserStatement extends SQLStatementImpl implements SQLCreateStatement {
|
||||
private SQLName user;
|
||||
private SQLExpr password;
|
||||
|
||||
@@ -60,4 +60,9 @@ public class SQLCreateUserStatement extends SQLStatementImpl {
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.USER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,6 +364,10 @@ public class SQLCreateViewStatement extends SQLStatementImpl implements SQLCreat
|
||||
this.script = x;
|
||||
}
|
||||
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.VIEW;
|
||||
}
|
||||
|
||||
public SQLCreateViewStatement clone() {
|
||||
SQLCreateViewStatement x = new SQLCreateViewStatement();
|
||||
|
||||
|
||||
@@ -18,4 +18,25 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
public interface SQLDDLStatement extends SQLStatement {
|
||||
default DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.OTHER;
|
||||
}
|
||||
|
||||
enum DDLObjectType {
|
||||
DATABASE,
|
||||
TABLE,
|
||||
VIEW,
|
||||
MATERIALIZED_VIEW,
|
||||
TABLE_SPACE,
|
||||
TABLE_GROUP,
|
||||
FUNCTION,
|
||||
TRIGGER,
|
||||
USER,
|
||||
ROLE,
|
||||
SEQUENCE,
|
||||
INDEX,
|
||||
PROCEDURE,
|
||||
TYPE,
|
||||
OTHER
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,14 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropCatalogStatement extends SQLStatementImpl implements SQLDropStatement, SQLReplaceable {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private boolean ifExists;
|
||||
private boolean external;
|
||||
|
||||
@@ -45,11 +42,11 @@ public class SQLDropCatalogStatement extends SQLStatementImpl implements SQLDrop
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
@@ -83,7 +80,7 @@ public class SQLDropCatalogStatement extends SQLStatementImpl implements SQLDrop
|
||||
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (name == expr) {
|
||||
setName(target);
|
||||
setName((SQLName) target);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,4 +186,9 @@ public class SQLDropDatabaseStatement extends SQLStatementImpl implements SQLDro
|
||||
public void setPhysical(boolean physical) {
|
||||
this.physical = physical;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.DATABASE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -25,7 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropEventStatement extends SQLStatementImpl implements SQLDropStatement {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private boolean ifExists;
|
||||
|
||||
public SQLDropEventStatement() {
|
||||
@@ -43,11 +43,11 @@ public class SQLDropEventStatement extends SQLStatementImpl implements SQLDropSt
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
|
||||
@@ -128,4 +128,9 @@ public class SQLDropIndexStatement extends SQLStatementImpl implements SQLDropSt
|
||||
public void setIfExists(boolean ifExists) {
|
||||
this.ifExists = ifExists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.INDEX;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -25,7 +26,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropLogFileGroupStatement extends SQLStatementImpl implements SQLDropStatement {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private SQLExpr engine;
|
||||
|
||||
public SQLDropLogFileGroupStatement() {
|
||||
@@ -44,11 +45,11 @@ public class SQLDropLogFileGroupStatement extends SQLStatementImpl implements SQ
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -25,7 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropMaterializedViewStatement extends SQLStatementImpl implements SQLDropStatement {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private boolean ifExists;
|
||||
|
||||
public SQLDropMaterializedViewStatement() {
|
||||
@@ -43,11 +43,11 @@ public class SQLDropMaterializedViewStatement extends SQLStatementImpl implement
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropOfflineModelStatement extends SQLStatementImpl implements SQLDropStatement, SQLReplaceable {
|
||||
protected SQLName name;
|
||||
protected boolean ifExists;
|
||||
|
||||
public SQLDropOfflineModelStatement() {
|
||||
}
|
||||
|
||||
public SQLDropOfflineModelStatement(DbType dbType) {
|
||||
super(dbType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, name);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SQLObject> getChildren() {
|
||||
List<SQLObject> children = new ArrayList<SQLObject>();
|
||||
if (name != null) {
|
||||
children.add(name);
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTableGroupName() {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name instanceof SQLName) {
|
||||
return name.getSimpleName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isIfExists() {
|
||||
return ifExists;
|
||||
}
|
||||
|
||||
public void setIfExists(boolean ifNotExists) {
|
||||
this.ifExists = ifNotExists;
|
||||
}
|
||||
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (name == expr) {
|
||||
setName((SQLName) target);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -25,7 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropOutlineStatement extends SQLStatementImpl implements SQLDropStatement {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private boolean ifExists;
|
||||
|
||||
public SQLDropOutlineStatement() {
|
||||
@@ -43,11 +43,11 @@ public class SQLDropOutlineStatement extends SQLStatementImpl implements SQLDrop
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
|
||||
@@ -58,4 +58,8 @@ public class SQLDropProcedureStatement extends SQLStatementImpl implements SQLDr
|
||||
this.ifExists = ifExists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.PROCEDURE;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -26,7 +26,7 @@ import java.util.List;
|
||||
|
||||
public class SQLDropResourceGroupStatement
|
||||
extends SQLStatementImpl implements SQLDropStatement {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private boolean ifExists;
|
||||
|
||||
public SQLDropResourceGroupStatement() {
|
||||
@@ -44,11 +44,11 @@ public class SQLDropResourceGroupStatement
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -25,7 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropResourceStatement extends SQLStatementImpl implements SQLDropStatement {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private boolean ifExists;
|
||||
|
||||
public SQLDropResourceStatement() {
|
||||
@@ -43,11 +43,11 @@ public class SQLDropResourceStatement extends SQLStatementImpl implements SQLDro
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
|
||||
@@ -74,4 +74,9 @@ public class SQLDropRoleStatement extends SQLStatementImpl implements SQLCreateS
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.ROLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,4 +88,9 @@ public class SQLDropSequenceStatement extends SQLStatementImpl implements SQLDro
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.SEQUENCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropServerStatement extends SQLStatementImpl implements SQLDropStatement, SQLReplaceable {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private boolean ifExists;
|
||||
|
||||
public SQLDropServerStatement() {
|
||||
@@ -41,11 +41,11 @@ public class SQLDropServerStatement extends SQLStatementImpl implements SQLDropS
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
|
||||
@@ -15,5 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
|
||||
public interface SQLDropStatement extends SQLDDLStatement {
|
||||
default SQLName getName() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,4 +87,8 @@ public class SQLDropTableGroupStatement extends SQLStatementImpl implements SQLD
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.TABLE_GROUP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,4 +92,9 @@ public class SQLDropTableSpaceStatement extends SQLStatementImpl implements SQLD
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.TABLE_SPACE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,4 +172,17 @@ public class SQLDropTableStatement extends SQLStatementImpl implements SQLDropSt
|
||||
}
|
||||
this.where = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.TABLE;
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
if (tableSources.size() == 1) {
|
||||
SQLExprTableSource dataSource0 = tableSources.get(0);
|
||||
return dataSource0.getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,4 +75,9 @@ public class SQLDropTriggerStatement extends SQLStatementImpl implements SQLDrop
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.TRIGGER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDropTypeStatement extends SQLStatementImpl implements SQLDropStatement, SQLReplaceable {
|
||||
private SQLExpr name;
|
||||
private SQLName name;
|
||||
private boolean ifExists;
|
||||
|
||||
public SQLDropTypeStatement() {
|
||||
@@ -41,11 +41,11 @@ public class SQLDropTypeStatement extends SQLStatementImpl implements SQLDropSta
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr x) {
|
||||
public void setName(SQLName x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
@@ -77,4 +77,9 @@ public class SQLDropTypeStatement extends SQLStatementImpl implements SQLDropSta
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,4 +78,9 @@ public class SQLDropUserStatement extends SQLStatementImpl implements SQLDropSta
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.USER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,4 +109,9 @@ public class SQLDropViewStatement extends SQLStatementImpl implements SQLDropSta
|
||||
public List getChildren() {
|
||||
return tableSources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DDLObjectType getDDLObjectType() {
|
||||
return DDLObjectType.VIEW;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.odps.ast;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class OdpsCopyStmt extends OdpsStatementImpl {
|
||||
private String arguments;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((OdpsASTVisitor) visitor);
|
||||
}
|
||||
|
||||
public void accept0(OdpsASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public String getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public void setArguments(String arguments) {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.odps.ast;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class OdpsPAIStmt extends OdpsStatementImpl {
|
||||
private String arguments;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((OdpsASTVisitor) visitor);
|
||||
}
|
||||
|
||||
public void accept0(OdpsASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public String getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public void setArguments(String arguments) {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
}
|
||||
+1
@@ -254,6 +254,7 @@ public class OdpsCreateTableParser extends SQLCreateTableParser {
|
||||
case TABLE:
|
||||
case PARTITION:
|
||||
case SEQUENCE:
|
||||
case VARIANT:
|
||||
break;
|
||||
default:
|
||||
throw new ParserException("expect identifier. " + lexer.info());
|
||||
|
||||
@@ -309,6 +309,12 @@ public class OdpsStatementParser extends SQLStatementParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("alias")) {
|
||||
SQLStatement stmt = parseSet();
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("EXSTORE")) {
|
||||
lexer.nextToken();
|
||||
OdpsExstoreStatement stmt = new OdpsExstoreStatement();
|
||||
@@ -331,6 +337,40 @@ public class OdpsStatementParser extends SQLStatementParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("PAI")) {
|
||||
lexer.nextToken();
|
||||
int semiPos = lexer.text.indexOf(';', lexer.pos());
|
||||
while (semiPos != -1 && semiPos + 2 < lexer.text.length()) {
|
||||
char next = lexer.text.charAt(semiPos + 1);
|
||||
if (next == '"' || next == '\'') {
|
||||
semiPos = lexer.text.indexOf(';', semiPos + 1);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
String arguments;
|
||||
if (semiPos != -1) {
|
||||
int count = semiPos - lexer.pos();
|
||||
arguments = lexer.subString(lexer.pos(), count);
|
||||
lexer.reset(semiPos);
|
||||
} else {
|
||||
arguments = lexer.subString(lexer.pos());
|
||||
lexer.reset(lexer.text.length());
|
||||
}
|
||||
lexer.nextToken();
|
||||
|
||||
OdpsPAIStmt stmt = new OdpsPAIStmt();
|
||||
stmt.setArguments(arguments);
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("COPY")) {
|
||||
SQLStatement stmt = parseCopy();
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.KILL)) {
|
||||
SQLStatement stmt = parseKill();
|
||||
statementList.add(stmt);
|
||||
@@ -1199,6 +1239,8 @@ public class OdpsStatementParser extends SQLStatementParser {
|
||||
if (identifierEquals("SETPROJECT")) {
|
||||
lexer.nextToken();
|
||||
setProject = true;
|
||||
} else if (dbType == DbType.odps && identifierEquals("ALIAS")) {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
accept(Token.SET);
|
||||
}
|
||||
@@ -1543,4 +1585,23 @@ public class OdpsStatementParser extends SQLStatementParser {
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseCopy() {
|
||||
lexer.nextToken();
|
||||
int semiPos = lexer.text.indexOf(';', lexer.pos());
|
||||
String arguments;
|
||||
if (semiPos != -1) {
|
||||
int count = semiPos - lexer.pos();
|
||||
arguments = lexer.subString(lexer.pos(), count);
|
||||
lexer.reset(semiPos);
|
||||
} else {
|
||||
arguments = lexer.subString(lexer.pos());
|
||||
lexer.reset(lexer.text.length());
|
||||
}
|
||||
lexer.nextToken();
|
||||
|
||||
OdpsCopyStmt stmt = new OdpsCopyStmt();
|
||||
stmt.setArguments(arguments);
|
||||
return stmt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,4 +272,18 @@ public interface OdpsASTVisitor extends HiveASTVisitor {
|
||||
default void endVisit(OdpsUndoTableStatement x) {
|
||||
}
|
||||
|
||||
default boolean visit(OdpsPAIStmt x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void endVisit(OdpsPAIStmt x) {
|
||||
}
|
||||
|
||||
default boolean visit(OdpsCopyStmt x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void endVisit(OdpsCopyStmt x) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1097,4 +1097,16 @@ public class OdpsOutputVisitor extends HiveOutputVisitor implements OdpsASTVisit
|
||||
printExpr(x.getPackageName());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(OdpsPAIStmt x) {
|
||||
print0(ucase ? "PAI " : "pai ");
|
||||
print0(x.getArguments());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(OdpsCopyStmt x) {
|
||||
print0(ucase ? "COPY " : "copy ");
|
||||
print0(x.getArguments());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +142,10 @@ public class Lexer {
|
||||
return text.substring(offset, offset + count);
|
||||
}
|
||||
|
||||
public final String subString(int offset) {
|
||||
return text.substring(offset);
|
||||
}
|
||||
|
||||
public final char[] sub_chars(int offset, int count) {
|
||||
char[] chars = new char[count];
|
||||
text.getChars(offset, offset + count, chars, 0);
|
||||
@@ -1132,12 +1136,14 @@ public class Lexer {
|
||||
}
|
||||
stringVal = null;
|
||||
mark = pos;
|
||||
while (!isWhitespace(ch) && ch != ';') {
|
||||
while (!isWhitespace(ch) && ch != ';' && pos < text.length()) {
|
||||
ch = charAt(++pos);
|
||||
}
|
||||
bufPos = pos - mark;
|
||||
|
||||
ch = charAt(++pos);
|
||||
if (ch != ';') {
|
||||
ch = charAt(++pos);
|
||||
}
|
||||
|
||||
token = LITERAL_PATH;
|
||||
}
|
||||
@@ -1147,7 +1153,13 @@ public class Lexer {
|
||||
ch = charAt(++pos);
|
||||
}
|
||||
|
||||
if (isFirstIdentifierChar(ch) || ch == '{') {
|
||||
char first = ch;
|
||||
if (first == '$') {
|
||||
scanVariable();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isFirstIdentifierChar(first) || first == '{') {
|
||||
stringVal = null;
|
||||
mark = pos;
|
||||
while (ch != ';' && ch != EOI) {
|
||||
@@ -2275,12 +2287,25 @@ public class Lexer {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ident && isWhitespace(ch)) {
|
||||
break;
|
||||
if (ident && ch == '$') {
|
||||
if (charAt(pos + 1) == '{') {
|
||||
bufPos++;
|
||||
ident = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (ident) {
|
||||
if (isWhitespace(ch)) {
|
||||
pos--;
|
||||
break;
|
||||
} else if (ch == ',' || ch == ')' || ch == '(' || ch == ';') {
|
||||
pos--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch != '}' && !ident) {
|
||||
@@ -2289,10 +2314,11 @@ public class Lexer {
|
||||
++pos;
|
||||
bufPos++;
|
||||
|
||||
char endChar = ch;
|
||||
this.ch = charAt(pos);
|
||||
|
||||
if (dbType == DbType.odps) {
|
||||
while (isIdentifierChar(this.ch) && ch != ';') {
|
||||
if (dbType == DbType.odps && !isWhitespace(endChar)) {
|
||||
while (isIdentifierChar(this.ch) && ch != ';') {
|
||||
++pos;
|
||||
bufPos++;
|
||||
this.ch = charAt(pos);
|
||||
@@ -2515,7 +2541,9 @@ public class Lexer {
|
||||
bufPos++;
|
||||
break;
|
||||
} else if (ch == EOI) {
|
||||
break;
|
||||
if (pos >= text.length()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == '\n') {
|
||||
|
||||
@@ -81,7 +81,7 @@ public class SQLExprParser extends SQLParser {
|
||||
if (lexer.token == Token.STAR) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLExpr expr = new SQLAllColumnExpr();
|
||||
SQLAllColumnExpr expr = new SQLAllColumnExpr();
|
||||
|
||||
if (lexer.token == Token.DOT) {
|
||||
lexer.nextToken();
|
||||
@@ -89,6 +89,15 @@ public class SQLExprParser extends SQLParser {
|
||||
return new SQLPropertyExpr(expr, "*");
|
||||
}
|
||||
|
||||
if (lexer.token == Token.EXCEPT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
List<SQLExpr> except = new ArrayList<>();
|
||||
this.exprList(except, expr);
|
||||
expr.setExcept(except);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
@@ -1958,7 +1967,21 @@ public class SQLExprParser extends SQLParser {
|
||||
protected SQLExpr dotRest(SQLExpr expr) {
|
||||
if (lexer.token == Token.STAR) {
|
||||
lexer.nextToken();
|
||||
expr = new SQLPropertyExpr(expr, "*");
|
||||
if (lexer.token == Token.EXCEPT) {
|
||||
SQLAllColumnExpr allColumnExpr = new SQLAllColumnExpr();
|
||||
allColumnExpr.setOwner(expr);
|
||||
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
List<SQLExpr> except = new ArrayList<>();
|
||||
this.exprList(except, allColumnExpr);
|
||||
allColumnExpr.setExcept(except);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
expr = allColumnExpr;
|
||||
} else {
|
||||
expr = new SQLPropertyExpr(expr, "*");
|
||||
}
|
||||
} else {
|
||||
String name;
|
||||
long hash_lower = 0L;
|
||||
@@ -2008,7 +2031,7 @@ public class SQLExprParser extends SQLParser {
|
||||
&& ((SQLIdentifierExpr) expr).nameHashCode64() == FnvHash.Constants.WMSYS;
|
||||
expr = methodRest(expr, name, aggregate);
|
||||
} else {
|
||||
if (name.charAt(0) == '`') {
|
||||
if (name.length() > 0 && name.charAt(0) == '`') {
|
||||
if (lexer.isEnabled(SQLParserFeature.IgnoreNameQuotes)) {
|
||||
name = name.substring(1, name.length() - 1);
|
||||
}
|
||||
@@ -2369,7 +2392,9 @@ public class SQLExprParser extends SQLParser {
|
||||
return name;
|
||||
}
|
||||
|
||||
if (lexer.token != Token.LITERAL_ALIAS && lexer.token != Token.IDENTIFIER
|
||||
if (lexer.token != Token.LITERAL_ALIAS
|
||||
&& lexer.token != Token.IDENTIFIER
|
||||
&& lexer.token != Token.VARIANT
|
||||
&& (!lexer.getKeywords().containsValue(lexer.token))) {
|
||||
throw new ParserException("error, " + lexer.info());
|
||||
}
|
||||
|
||||
@@ -580,6 +580,16 @@ public class SQLParserUtils {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token == Token.FUNCTION || lexer.identifierEquals("FUNCTION")) {
|
||||
lexer.nextToken();
|
||||
lexer.nextToken();
|
||||
if (lexer.token == Token.AS) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token == Token.LITERAL_CHARS) {
|
||||
lexer.nextToken();
|
||||
token = lexer.token;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
lexer.startPos = sql.length();
|
||||
break;
|
||||
}
|
||||
@@ -590,8 +600,15 @@ public class SQLParserUtils {
|
||||
lexer.nextTokenForSet();
|
||||
token = lexer.token;
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("pai") || lexer.identifierEquals("jar")) {
|
||||
} else if (dbType == DbType.odps && (lexer.identifierEquals("pai") || lexer.identifierEquals("jar"))) {
|
||||
if (lexer.startPos - start > 0) {
|
||||
int semiIndex = sql.indexOf(';', lexer.startPos);
|
||||
if (semiIndex != -1) {
|
||||
lexer.pos = semiIndex - 1;
|
||||
lexer.nextToken();
|
||||
token = lexer.token;
|
||||
continue;
|
||||
}
|
||||
String str = sql.substring(start, lexer.startPos).trim();
|
||||
if (str.isEmpty()) {
|
||||
lexer.startPos = sql.length();
|
||||
@@ -605,7 +622,14 @@ public class SQLParserUtils {
|
||||
set = true;
|
||||
}
|
||||
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals("ADD") && (dbType == DbType.hive || dbType == DbType.odps)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals("JAR")) {
|
||||
lexer.nextPath();
|
||||
}
|
||||
} else {
|
||||
lexer.nextToken();
|
||||
}
|
||||
token = lexer.token;
|
||||
}
|
||||
|
||||
@@ -735,9 +759,9 @@ public class SQLParserUtils {
|
||||
if (lexer.identifierEquals("JAR")) {
|
||||
lexer.nextPath();
|
||||
}
|
||||
} else {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
lexer.nextToken();
|
||||
token = lexer.token;
|
||||
}
|
||||
|
||||
|
||||
@@ -861,6 +861,8 @@ public class SQLStatementParser extends SQLParser {
|
||||
stmt = x;
|
||||
} else if (lexer.identifierEquals("MATERIALIZED")) {
|
||||
stmt = parseDropMaterializedView();
|
||||
} else if (lexer.identifierEquals("OFFLINEMODEL")) {
|
||||
stmt = parseDropOfflineModel();
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
@@ -970,6 +972,25 @@ public class SQLStatementParser extends SQLParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseDropOfflineModel() {
|
||||
if (lexer.token() == Token.DROP) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLDropOfflineModelStatement stmt = new SQLDropOfflineModelStatement();
|
||||
stmt.setDbType(dbType);
|
||||
|
||||
acceptIdentifier("OFFLINEMODEL");
|
||||
|
||||
if (lexer.token == Token.IF) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EXISTS);
|
||||
stmt.setIfExists(true);
|
||||
}
|
||||
|
||||
stmt.setName(this.exprParser.name());
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected SQLStatement parseDropCatalog() {
|
||||
accept(Token.DROP);
|
||||
|
||||
@@ -2148,6 +2169,14 @@ public class SQLStatementParser extends SQLParser {
|
||||
accept(RPAREN);
|
||||
stmt.addItem(alterTablePartition);
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("ARCHIVE")) {
|
||||
SQLAlterTableArchive archive = new SQLAlterTableArchive();
|
||||
for (SQLAssignItem condition : renamePartition.getPartition()) {
|
||||
archive.getPartition().add(condition);
|
||||
condition.setParent(archive);
|
||||
}
|
||||
stmt.addItem(archive);
|
||||
continue;
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.ADD)) {
|
||||
alterTableAdd(stmt);
|
||||
continue;
|
||||
@@ -2189,14 +2218,15 @@ public class SQLStatementParser extends SQLParser {
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.ARCHIVE)) {
|
||||
lexer.nextToken();
|
||||
|
||||
accept(Token.PARTITION);
|
||||
if (lexer.token == PARTITION) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLAlterTableArchivePartition item = new SQLAlterTableArchivePartition();
|
||||
accept(Token.LPAREN);
|
||||
parseAssignItems(item.getPartitions(), item, false);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
stmt.addItem(item);
|
||||
SQLAlterTableArchivePartition item = new SQLAlterTableArchivePartition();
|
||||
accept(Token.LPAREN);
|
||||
parseAssignItems(item.getPartitions(), item, false);
|
||||
accept(Token.RPAREN);
|
||||
stmt.addItem(item);
|
||||
}
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.UNARCHIVE)) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
@@ -2101,7 +2101,21 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
|
||||
public boolean visit(SQLAllColumnExpr x) {
|
||||
SQLExpr owner = x.getOwner();
|
||||
if (owner != null) {
|
||||
printExpr(owner);
|
||||
print('.');
|
||||
}
|
||||
|
||||
print('*');
|
||||
|
||||
List<SQLExpr> except = x.getExcept();
|
||||
if (except != null) {
|
||||
print(ucase ? " EXCEPT(" : "except(");
|
||||
printAndAccept(except, ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6746,6 +6760,18 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableArchive x) {
|
||||
if (!x.getPartition().isEmpty()) {
|
||||
print0(ucase ? "PARTITION (" : "partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print0(") ");
|
||||
}
|
||||
|
||||
print0(ucase ? "ARCHIVE" : "archive");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDisableLifecycle x) {
|
||||
if (!x.getPartition().isEmpty()) {
|
||||
@@ -10242,6 +10268,19 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
@Override
|
||||
public boolean visit(SQLDropOutlineStatement x) {
|
||||
print0(ucase ? "DROP OUTLINE " : "drop outline ");
|
||||
if (x.isIfExists()) {
|
||||
print0(ucase ? "IF EXISTS " : "if exists ");
|
||||
}
|
||||
x.getName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropOfflineModelStatement x) {
|
||||
print0(ucase ? "DROP OFFLINEMODEL " : "drop offlinemodel ");
|
||||
if (x.isIfExists()) {
|
||||
print0(ucase ? "IF EXISTS " : "if exists ");
|
||||
}
|
||||
x.getName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1045,6 +1045,13 @@ public interface SQLASTVisitor {
|
||||
default void endVisit(SQLAlterTablePartition x) {
|
||||
}
|
||||
|
||||
default boolean visit(SQLAlterTableArchive x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void endVisit(SQLAlterTableArchive x) {
|
||||
}
|
||||
|
||||
default boolean visit(SQLAlterTablePartition x) {
|
||||
return true;
|
||||
}
|
||||
@@ -1990,6 +1997,13 @@ public interface SQLASTVisitor {
|
||||
default void endVisit(SQLDropOutlineStatement x) {
|
||||
}
|
||||
|
||||
default boolean visit(SQLDropOfflineModelStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void endVisit(SQLDropOfflineModelStatement x) {
|
||||
}
|
||||
|
||||
default boolean visit(SQLAlterOutlineStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user