use of com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause in project druid by alibaba.
the class HiveSchemaStatVisitor method visit.
@Override
public boolean visit(HiveInsertStatement x) {
if (repository != null && x.getParent() == null) {
repository.resolve(x);
}
SQLWithSubqueryClause with = x.getWith();
if (with != null) {
with.accept(this);
}
setMode(x, TableStat.Mode.Insert);
SQLExprTableSource tableSource = x.getTableSource();
SQLExpr tableName = tableSource.getExpr();
if (tableName instanceof SQLName) {
TableStat stat = getTableStat((SQLName) tableName);
stat.incrementInsertCount();
List<SQLExpr> columns = x.getColumns();
for (SQLExpr column : columns) {
if (column instanceof SQLIdentifierExpr) {
addColumn((SQLName) tableName, ((SQLIdentifierExpr) column).normalizedName());
}
}
}
for (SQLAssignItem partition : x.getPartitions()) {
partition.accept(this);
}
accept(x.getQuery());
return false;
}
use of com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause in project druid by alibaba.
the class SQLSelectParser method withSubquery.
protected void withSubquery(SQLSelect select) {
if (lexer.token() == Token.WITH) {
lexer.nextToken();
SQLWithSubqueryClause withQueryClause = new SQLWithSubqueryClause();
if (lexer.token == Token.RECURSIVE || identifierEquals("RECURSIVE")) {
lexer.nextToken();
withQueryClause.setRecursive(true);
}
for (; ; ) {
SQLWithSubqueryClause.Entry entry = new SQLWithSubqueryClause.Entry();
entry.setParent(withQueryClause);
entry.setName((SQLIdentifierExpr) this.exprParser.name());
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
exprParser.names(entry.getColumns());
accept(Token.RPAREN);
}
accept(Token.AS);
accept(Token.LPAREN);
entry.setSubQuery(select());
accept(Token.RPAREN);
withQueryClause.addEntry(entry);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
select.setWithSubQuery(withQueryClause);
}
}
use of com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause in project druid by alibaba.
the class ClickhouseStatementParser method parseWithQuery.
@Override
public SQLWithSubqueryClause parseWithQuery() {
SQLWithSubqueryClause withQueryClause = new SQLWithSubqueryClause();
if (lexer.hasComment() && lexer.isKeepComments()) {
withQueryClause.addBeforeComment(lexer.readAndResetComments());
}
accept(Token.WITH);
for (; ; ) {
SQLWithSubqueryClause.Entry entry = new SQLWithSubqueryClause.Entry();
entry.setParent(withQueryClause);
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
switch(lexer.token()) {
case VALUES:
case WITH:
case SELECT:
entry.setSubQuery(this.createSQLSelectParser().select());
break;
default:
break;
}
accept(Token.RPAREN);
} else {
entry.setExpr(exprParser.expr());
}
accept(Token.AS);
String alias = this.lexer.stringVal();
lexer.nextToken();
entry.setAlias(alias);
withQueryClause.addEntry(entry);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
return withQueryClause;
}
use of com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause in project druid by alibaba.
the class SQLASTVisitorAdapterTest method test_adapter.
public void test_adapter() throws Exception {
SQLASTVisitorAdapter adapter = new SQLASTVisitorAdapter();
new SQLBinaryOpExpr().accept(adapter);
new SQLInListExpr().accept(adapter);
new SQLSelectQueryBlock().accept(adapter);
new SQLDropTableStatement().accept(adapter);
new SQLCreateTableStatement().accept(adapter);
new SQLDeleteStatement().accept(adapter);
new SQLCurrentOfCursorExpr().accept(adapter);
new SQLInsertStatement().accept(adapter);
new SQLUpdateStatement().accept(adapter);
new SQLNotNullConstraint().accept(adapter);
new SQLMethodInvokeExpr().accept(adapter);
new SQLCallStatement().accept(adapter);
new SQLSomeExpr().accept(adapter);
new SQLAnyExpr().accept(adapter);
new SQLAllExpr().accept(adapter);
new SQLDefaultExpr().accept(adapter);
new SQLCommentStatement().accept(adapter);
new SQLDropViewStatement().accept(adapter);
new SQLSavePointStatement().accept(adapter);
new SQLReleaseSavePointStatement().accept(adapter);
new SQLCreateDatabaseStatement().accept(adapter);
new SQLAlterTableDropIndex().accept(adapter);
new SQLOver().accept(adapter);
new SQLWithSubqueryClause().accept(adapter);
new SQLAlterTableAlterColumn().accept(adapter);
new SQLAlterTableStatement().accept(adapter);
new SQLAlterTableDisableConstraint().accept(adapter);
new SQLAlterTableEnableConstraint().accept(adapter);
new SQLColumnCheck().accept(adapter);
new SQLExprHint().accept(adapter);
new SQLAlterTableDropConstraint().accept(adapter);
}
Aggregations