use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OdpsStatementParser method parseSet.
public SQLStatement parseSet() {
List<String> comments = null;
if (lexer.isKeepComments() && lexer.hasComment()) {
comments = lexer.readAndResetComments();
}
accept(Token.SET);
if (identifierEquals("LABEL")) {
OdpsSetLabelStatement stmt = new OdpsSetLabelStatement();
if (comments != null) {
stmt.addBeforeComment(comments);
}
lexer.nextToken();
stmt.setLabel(lexer.stringVal());
lexer.nextToken();
accept(Token.TO);
if (lexer.token() == Token.USER) {
lexer.nextToken();
SQLName name = this.exprParser.name();
stmt.setUser(name);
return stmt;
}
accept(Token.TABLE);
SQLExpr expr = this.exprParser.name();
stmt.setTable(new SQLExprTableSource(expr));
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
this.exprParser.names(stmt.getColumns(), stmt);
accept(Token.RPAREN);
}
return stmt;
} else {
SQLSetStatement stmt = new SQLSetStatement(getDbType());
if (comments != null) {
stmt.addBeforeComment(comments);
}
parseAssignItems(stmt.getItems(), stmt);
return stmt;
}
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OdpsSchemaStatVisitor method visit.
@Override
public boolean visit(OdpsInsert x) {
setMode(x, TableStat.Mode.Insert);
setAliasMap();
SQLExprTableSource tableSource = x.getTableSource();
SQLExpr tableName = tableSource.getExpr();
if (tableName instanceof SQLName) {
String ident = ((SQLName) tableName).toString();
setCurrentTable(ident);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
Map<String, String> aliasMap = getAliasMap();
putAliasMap(aliasMap, tableSource.getAlias(), ident);
putAliasMap(aliasMap, ident, ident);
}
for (SQLAssignItem partition : x.getPartitions()) {
partition.accept(this);
}
accept(x.getQuery());
return false;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class MySqlSchemaStatVisitor method visit.
// DUAL
public boolean visit(MySqlDeleteStatement x) {
setAliasMap();
setMode(x, Mode.Delete);
accept(x.getFrom());
accept(x.getUsing());
x.getTableSource().accept(this);
if (x.getTableSource() instanceof SQLExprTableSource) {
SQLName tableName = (SQLName) ((SQLExprTableSource) x.getTableSource()).getExpr();
String ident = tableName.toString();
setCurrentTable(x, ident);
TableStat stat = this.getTableStat(ident);
stat.incrementDeleteCount();
}
accept(x.getWhere());
accept(x.getOrderBy());
accept(x.getLimit());
return false;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class PhoenixStatementParser method parseInsertColumns.
@Override
protected void parseInsertColumns(SQLInsertInto insert) {
if (lexer.token() == Token.RPAREN) {
return;
}
for (; ; ) {
SQLName expr = this.exprParser.name();
expr.setParent(insert);
insert.getColumns().add(expr);
if (lexer.token() == Token.IDENTIFIER) {
String text = lexer.stringVal();
if (text.equalsIgnoreCase("TINYINT") || text.equalsIgnoreCase("BIGINT") || text.equalsIgnoreCase("INTEGER") || text.equalsIgnoreCase("DOUBLE") || text.equalsIgnoreCase("DATE") || text.equalsIgnoreCase("VARCHAR")) {
expr.getAttributes().put("dataType", text);
lexer.nextToken();
} else if (text.equalsIgnoreCase("CHAR")) {
String dataType = text;
lexer.nextToken();
accept(Token.LPAREN);
SQLExpr char_len = this.exprParser.primary();
accept(Token.RPAREN);
dataType += ("(" + char_len.toString() + ")");
expr.getAttributes().put("dataType", dataType);
}
}
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OracleSchemaStatVisitor method visit.
public boolean visit(OracleSelectTableReference x) {
SQLExpr expr = x.getExpr();
if (expr instanceof SQLMethodInvokeExpr) {
SQLMethodInvokeExpr methodInvoke = (SQLMethodInvokeExpr) expr;
if ("TABLE".equalsIgnoreCase(methodInvoke.getMethodName()) && methodInvoke.getParameters().size() == 1) {
expr = methodInvoke.getParameters().get(0);
}
}
Map<String, String> aliasMap = getAliasMap();
if (expr instanceof SQLName) {
String ident;
if (expr instanceof SQLPropertyExpr) {
String owner = ((SQLPropertyExpr) expr).getOwner().toString();
String name = ((SQLPropertyExpr) expr).getName();
if (aliasMap.containsKey(owner)) {
owner = aliasMap.get(owner);
}
ident = owner + "." + name;
} else {
ident = expr.toString();
}
if (containsSubQuery(ident)) {
return false;
}
if ("DUAL".equalsIgnoreCase(ident)) {
return false;
}
x.putAttribute(ATTR_TABLE, ident);
TableStat stat = getTableStat(ident);
Mode mode = getMode();
switch(mode) {
case Delete:
stat.incrementDeleteCount();
break;
case Insert:
stat.incrementInsertCount();
break;
case Update:
stat.incrementUpdateCount();
break;
case Select:
stat.incrementSelectCount();
break;
case Merge:
stat.incrementMergeCount();
break;
default:
break;
}
putAliasMap(aliasMap, x.getAlias(), ident);
putAliasMap(aliasMap, ident, ident);
return false;
}
accept(x.getExpr());
return false;
}
Aggregations