improved odps & hive sql parser support.

This commit is contained in:
wenshao
2017-12-02 13:10:02 +08:00
parent f678fbc96b
commit 316f59e3d2
4 changed files with 123 additions and 0 deletions
@@ -31,6 +31,7 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
private SQLExprTableSource like;
protected SQLExpr storedBy;
protected SQLExpr lifecycle;
public OdpsCreateTableStatement(){
@@ -69,9 +70,21 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
this.acceptChild(visitor, partitionColumns);
this.acceptChild(visitor, clusteredBy);
this.acceptChild(visitor, sortedBy);
this.acceptChild(visitor, storedBy);
this.acceptChild(visitor, lifecycle);
this.acceptChild(visitor, select);
}
visitor.endVisit(this);
}
public SQLExpr getStoredBy() {
return storedBy;
}
public void setStoredBy(SQLExpr x) {
if (x != null) {
x.setParent(this);
}
this.storedBy = x;
}
}
@@ -15,6 +15,7 @@
*/
package com.alibaba.druid.sql.dialect.odps.parser;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
@@ -178,6 +179,19 @@ public class OdpsCreateTableParser extends SQLCreateTableParser {
lexer.nextToken();
stmt.setLifecycle(this.exprParser.expr());
}
while (lexer.identifierEquals(FnvHash.Constants.STORED)) {
lexer.nextToken();
if (lexer.token() == Token.AS) {
lexer.nextToken();
SQLName storedAs = this.exprParser.name();
stmt.setStoredAs(storedAs);
} else {
accept(Token.BY);
SQLExpr storedBy = this.exprParser.expr();
stmt.setStoredBy(storedBy);
}
}
return stmt;
}
@@ -161,6 +161,20 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
x.getLifecycle().accept(this);
}
SQLExpr storedBy = x.getStoredBy();
if (storedBy != null) {
println();
print0(ucase ? "STORED BY " : "stored by ");
storedBy.accept(this);
}
SQLExpr storedAs = x.getStoredAs();
if (storedAs != null) {
println();
print0(ucase ? "STORED AS " : "stored as ");
storedAs.accept(this);
}
if (x.getSelect() != null) {
println();
print0(ucase ? "AS" : "as");