mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser about the desc and explain parts of the code
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDescribeStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLObjectType;
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class OdpsDescStmt extends SQLDescribeStatement {
|
||||
|
||||
private SQLObjectType objectType;
|
||||
|
||||
private List<SQLExpr> partition = new ArrayList<SQLExpr>();
|
||||
|
||||
public OdpsDescStmt() {
|
||||
this.setDbType(JdbcConstants.ODPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((OdpsASTVisitor) visitor);
|
||||
}
|
||||
|
||||
protected void accept0(OdpsASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, object);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLObjectType getObjectType() {
|
||||
return objectType;
|
||||
}
|
||||
|
||||
public void setObjectType(SQLObjectType objectType) {
|
||||
this.objectType = objectType;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getPartition() {
|
||||
return partition;
|
||||
}
|
||||
|
||||
public void setPartition(List<SQLExpr> partition) {
|
||||
this.partition = partition;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +33,6 @@ import com.alibaba.druid.sql.ast.statement.SQLShowTablesStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsAddStatisticStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsAnalyzeTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsDescStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsGrantStmt;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
|
||||
@@ -179,7 +178,7 @@ public class OdpsStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.DESC || identifierEquals("DESCRIBE")) {
|
||||
OdpsDescStmt stmt = parseDescribe();
|
||||
SQLStatement stmt = parseDescribe();
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
@@ -589,42 +588,4 @@ public class OdpsStatementParser extends SQLStatementParser {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public OdpsDescStmt parseDescribe() {
|
||||
if (lexer.token() == Token.DESC || identifierEquals("DESCRIBE")) {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("expect DESC, actual " + lexer.token());
|
||||
}
|
||||
|
||||
OdpsDescStmt stmt = new OdpsDescStmt();
|
||||
if (identifierEquals("ROLE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setObjectType(SQLObjectType.ROLE);
|
||||
} else if (identifierEquals("PACKAGE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setObjectType(SQLObjectType.PACKAGE);
|
||||
} else if (identifierEquals("INSTANCE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setObjectType(SQLObjectType.INSTANCE);
|
||||
}
|
||||
stmt.setObject(this.exprParser.name());
|
||||
|
||||
if (lexer.token() == Token.PARTITION) {
|
||||
lexer.nextToken();
|
||||
this.accept(Token.LPAREN);
|
||||
for (;;) {
|
||||
stmt.getPartition().add(this.exprParser.expr());
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
if (lexer.token() == Token.RPAREN) {
|
||||
lexer.nextToken();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return stmt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,10 +104,6 @@ public interface OdpsASTVisitor extends SQLASTVisitor {
|
||||
|
||||
boolean visit(OdpsGrantStmt x);
|
||||
|
||||
void endVisit(OdpsDescStmt x);
|
||||
|
||||
boolean visit(OdpsDescStmt x);
|
||||
|
||||
void endVisit(OdpsLateralViewTableSource x);
|
||||
|
||||
boolean visit(OdpsLateralViewTableSource x);
|
||||
|
||||
@@ -231,16 +231,6 @@ public class OdpsASTVisitorAdapter extends SQLASTVisitorAdapter implements OdpsA
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsDescStmt x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsDescStmt x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsLateralViewTableSource x) {
|
||||
|
||||
|
||||
@@ -815,31 +815,6 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsDescStmt x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsDescStmt x) {
|
||||
print0(ucase ? "DESC " : "desc ");
|
||||
if (x.getObjectType() != null) {
|
||||
print0(x.getObjectType().name());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
if(x.getObject() != null) {
|
||||
x.getObject().accept(this);
|
||||
}
|
||||
|
||||
if (x.getPartition().size() > 0) {
|
||||
print0(ucase ? " PARTITION (" : " partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print(')');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsLateralViewTableSource x) {
|
||||
|
||||
|
||||
@@ -264,16 +264,6 @@ public class OdpsSchemaStatVisitor extends SchemaStatVisitor implements OdpsASTV
|
||||
return super.visit((SQLGrantStatement) x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsDescStmt x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsDescStmt x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OdpsLateralViewTableSource x) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user