mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved odps support
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.druid.sql.dialect.odps.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
|
||||
@@ -9,7 +10,7 @@ import java.util.ArrayList;
|
||||
|
||||
public class OdpsExstoreStatement extends OdpsStatementImpl {
|
||||
private SQLExprTableSource table;
|
||||
private final List<SQLExpr> partitions = new ArrayList<SQLExpr>();
|
||||
private final List<SQLAssignItem> partitions = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void accept0(OdpsASTVisitor v) {
|
||||
@@ -31,7 +32,7 @@ public class OdpsExstoreStatement extends OdpsStatementImpl {
|
||||
this.table = x;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getPartitions() {
|
||||
public List<SQLAssignItem> getPartitions() {
|
||||
return partitions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,9 +318,7 @@ public class OdpsStatementParser extends SQLStatementParser {
|
||||
SQLExpr table = this.exprParser.expr();
|
||||
stmt.setTable(new SQLExprTableSource(table));
|
||||
accept(Token.PARTITION);
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.exprList(stmt.getPartitions(), stmt);
|
||||
accept(Token.RPAREN);
|
||||
this.exprParser.parseAssignItem(stmt.getPartitions(), stmt);
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -100,6 +100,19 @@ public class OdpsSchemaStatVisitor extends HiveSchemaStatVisitor implements Odps
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsExstoreStatement x) {
|
||||
SQLExprTableSource table = x.getTable();
|
||||
TableStat stat = getTableStatWithUnwrap(table.getExpr());
|
||||
if (stat != null) {
|
||||
stat.incrementSelectCount();
|
||||
}
|
||||
|
||||
resolvePartitions(table, x.getPartitions());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void resolvePartitions(SQLExprTableSource table, List<SQLAssignItem> parttions) {
|
||||
for (SQLAssignItem partition : parttions) {
|
||||
SQLExpr target = partition.getTarget();
|
||||
|
||||
@@ -30,36 +30,9 @@ import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.*;
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isFirstIdentifierChar;
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isIdentifierChar;
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isWhitespace;
|
||||
import static com.alibaba.druid.sql.parser.LayoutCharacters.EOI;
|
||||
import static com.alibaba.druid.sql.parser.SQLParserFeature.*;
|
||||
import static com.alibaba.druid.sql.parser.SQLParserFeature.KeepComments;
|
||||
import static com.alibaba.druid.sql.parser.SQLParserFeature.KeepSourceLocation;
|
||||
import static com.alibaba.druid.sql.parser.SQLParserFeature.OptimizedForParameterized;
|
||||
import static com.alibaba.druid.sql.parser.SQLParserFeature.SkipComments;
|
||||
import static com.alibaba.druid.sql.parser.Token.*;
|
||||
import static com.alibaba.druid.sql.parser.Token.COLON;
|
||||
import static com.alibaba.druid.sql.parser.Token.COLONCOLON;
|
||||
import static com.alibaba.druid.sql.parser.Token.COLONEQ;
|
||||
import static com.alibaba.druid.sql.parser.Token.COMMA;
|
||||
import static com.alibaba.druid.sql.parser.Token.DOT;
|
||||
import static com.alibaba.druid.sql.parser.Token.EOF;
|
||||
import static com.alibaba.druid.sql.parser.Token.EQ;
|
||||
import static com.alibaba.druid.sql.parser.Token.EQEQ;
|
||||
import static com.alibaba.druid.sql.parser.Token.EQGT;
|
||||
import static com.alibaba.druid.sql.parser.Token.ERROR;
|
||||
import static com.alibaba.druid.sql.parser.Token.IDENTIFIER;
|
||||
import static com.alibaba.druid.sql.parser.Token.LBRACE;
|
||||
import static com.alibaba.druid.sql.parser.Token.LBRACKET;
|
||||
import static com.alibaba.druid.sql.parser.Token.LITERAL_ALIAS;
|
||||
import static com.alibaba.druid.sql.parser.Token.LITERAL_CHARS;
|
||||
import static com.alibaba.druid.sql.parser.Token.LITERAL_PATH;
|
||||
import static com.alibaba.druid.sql.parser.Token.LPAREN;
|
||||
import static com.alibaba.druid.sql.parser.Token.RBRACE;
|
||||
import static com.alibaba.druid.sql.parser.Token.RBRACKET;
|
||||
import static com.alibaba.druid.sql.parser.Token.RPAREN;
|
||||
|
||||
/**
|
||||
* @author wenshao [szujobs@hotmail.com]
|
||||
@@ -2252,6 +2225,40 @@ public class Lexer {
|
||||
}
|
||||
}
|
||||
|
||||
stringVal = addSymbol();
|
||||
token = Token.VARIANT;
|
||||
return;
|
||||
} else if (c1 == '$' && charAt(pos + 2) == '{') {
|
||||
pos += 2;
|
||||
bufPos += 2;
|
||||
|
||||
for (;;) {
|
||||
ch = charAt(++pos);
|
||||
|
||||
if (ch == '}') {
|
||||
break;
|
||||
}
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch != '}') {
|
||||
throw new ParserException("syntax error. " + info());
|
||||
}
|
||||
++pos;
|
||||
bufPos++;
|
||||
|
||||
this.ch = charAt(pos);
|
||||
|
||||
if (dbType == DbType.odps) {
|
||||
while (isIdentifierChar(this.ch)) {
|
||||
++pos;
|
||||
bufPos++;
|
||||
this.ch = charAt(pos);
|
||||
}
|
||||
}
|
||||
|
||||
stringVal = addSymbol();
|
||||
token = Token.VARIANT;
|
||||
return;
|
||||
|
||||
@@ -2327,7 +2327,10 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
for (SQLAlterTableItem item : x.getItems()) {
|
||||
item.setParent(x);
|
||||
if (item instanceof SQLAlterTableAddPartition) {
|
||||
if (item instanceof SQLAlterTableAddPartition
|
||||
|| item instanceof SQLAlterTableRenamePartition
|
||||
|| item instanceof SQLAlterTableMergePartition
|
||||
) {
|
||||
stat.incrementAddPartitionCount();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user