refactor sql parser for hive & odps support

This commit is contained in:
wenshao
2017-11-13 21:37:45 +08:00
parent 7a2609826a
commit c73191ad41
5 changed files with 64 additions and 81 deletions
@@ -31,13 +31,6 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
private SQLExprTableSource like;
protected List<SQLColumnDefinition> partitionColumns = new ArrayList<SQLColumnDefinition>(2);
protected final List<SQLName> clusteredBy = new ArrayList<SQLName>();
protected final List<SQLName> sortedBy = new ArrayList<SQLName>();
protected int buckets;
protected SQLExpr lifecycle;
public OdpsCreateTableStatement(){
@@ -56,17 +49,6 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
this.like = like;
}
public List<SQLColumnDefinition> getPartitionColumns() {
return partitionColumns;
}
public void addPartitionColumn(SQLColumnDefinition column) {
if (column != null) {
column.setParent(this);
}
this.partitionColumns.add(column);
}
public SQLExpr getLifecycle() {
return lifecycle;
}
@@ -92,20 +74,4 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
}
visitor.endVisit(this);
}
public List<SQLName> getClusteredBy() {
return clusteredBy;
}
public List<SQLName> getSortedBy() {
return sortedBy;
}
public int getBuckets() {
return buckets;
}
public void setBuckets(int buckets) {
this.buckets = buckets;
}
}
@@ -19,6 +19,7 @@ import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsCreateTableStatement;
import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.parser.SQLCreateTableParser;
@@ -150,7 +151,15 @@ public class OdpsCreateTableParser extends SQLCreateTableParser {
lexer.nextToken();
accept(Token.BY);
accept(Token.LPAREN);
this.exprParser.names(stmt.getSortedBy());
for (; ; ) {
SQLSelectOrderByItem item = this.exprParser.parseSelectOrderByItem();
stmt.addSortedByItem(item);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
}
@@ -139,11 +139,11 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
print(')');
}
List<SQLName> sortedBy = x.getSortedBy();
List<SQLSelectOrderByItem> sortedBy = x.getSortedBy();
if (sortedBy.size() > 0) {
println();
print0(ucase ? "SORTED BY (" : "sorted by (");
printAndAccept(sortedBy, ",");
printAndAccept(sortedBy, ", ");
print(')');
}