use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OracleCreateTableParser method partitionByRange.
protected SQLPartitionByRange partitionByRange() {
acceptIdentifier("RANGE");
accept(Token.LPAREN);
SQLPartitionByRange clause = new SQLPartitionByRange();
for (; ; ) {
SQLName column = this.exprParser.name();
clause.addColumn(column);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
if (lexer.token() == Token.INTERVAL) {
lexer.nextToken();
accept(Token.LPAREN);
clause.setInterval(this.exprParser.expr());
accept(Token.RPAREN);
}
parsePartitionByRest(clause);
return clause;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OracleExprParser method name.
public SQLName name() {
SQLName name = super.name();
if (lexer.token() == Token.MONKEYS_AT) {
lexer.nextToken();
if (lexer.token() != Token.IDENTIFIER) {
throw new ParserException("syntax error, expect identifier, but " + lexer.token());
}
OracleDbLinkExpr dbLink = new OracleDbLinkExpr();
dbLink.setExpr(name);
dbLink.setDbLink(lexer.stringVal());
lexer.nextToken();
return dbLink;
}
return name;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OracleExprParser method parseConstaint.
public OracleConstraint parseConstaint() {
OracleConstraint constraint = (OracleConstraint) super.parseConstaint();
for (; ; ) {
if (lexer.token() == Token.EXCEPTIONS) {
lexer.nextToken();
accept(Token.INTO);
SQLName exceptionsInto = this.name();
constraint.setExceptionsInto(exceptionsInto);
continue;
}
if (lexer.token() == Token.DISABLE) {
lexer.nextToken();
constraint.setEnable(false);
continue;
}
if (lexer.token() == Token.ENABLE) {
lexer.nextToken();
constraint.setEnable(true);
continue;
}
if (lexer.token() == Token.INITIALLY) {
lexer.nextToken();
if (lexer.token() == Token.IMMEDIATE) {
lexer.nextToken();
constraint.setInitially(Initially.IMMEDIATE);
} else {
accept(Token.DEFERRED);
constraint.setInitially(Initially.DEFERRED);
}
continue;
}
if (lexer.token() == Token.NOT) {
lexer.nextToken();
if (identifierEquals("DEFERRABLE")) {
lexer.nextToken();
constraint.setDeferrable(false);
continue;
}
throw new ParserException("TODO " + lexer.token());
}
if (identifierEquals("DEFERRABLE")) {
lexer.nextToken();
constraint.setDeferrable(true);
continue;
}
break;
}
return constraint;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OdpsCreateTableParser method parseCrateTable.
public SQLCreateTableStatement parseCrateTable(boolean acceptCreate) {
OdpsCreateTableStatement stmt = new OdpsCreateTableStatement();
if (acceptCreate) {
accept(Token.CREATE);
}
accept(Token.TABLE);
if (lexer.token() == Token.IF || identifierEquals("IF")) {
lexer.nextToken();
accept(Token.NOT);
accept(Token.EXISTS);
stmt.setIfNotExiists(true);
}
stmt.setName(this.exprParser.name());
if (identifierEquals("LIFECYCLE")) {
lexer.nextToken();
stmt.setLifecycle(this.exprParser.expr());
}
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
SQLName name = this.exprParser.name();
stmt.setLike(name);
} else if (lexer.token() == Token.AS) {
lexer.nextToken();
OdpsSelectParser selectParser = new OdpsSelectParser(this.exprParser);
SQLSelect select = selectParser.select();
stmt.setSelect(select);
} else {
accept(Token.LPAREN);
if (lexer.isKeepComments() && lexer.hasComment()) {
stmt.addBodyBeforeComment(lexer.readAndResetComments());
}
for (; ; ) {
if (lexer.token() != Token.IDENTIFIER) {
throw new ParserException("expect identifier");
}
SQLColumnDefinition column = this.exprParser.parseColumn();
stmt.getTableElementList().add(column);
if (lexer.isKeepComments() && lexer.hasComment()) {
column.addAfterComment(lexer.readAndResetComments());
}
if (!(lexer.token() == (Token.COMMA))) {
break;
} else {
lexer.nextToken();
if (lexer.isKeepComments() && lexer.hasComment()) {
column.addAfterComment(lexer.readAndResetComments());
}
}
}
accept(Token.RPAREN);
}
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
stmt.setComment(this.exprParser.primary());
}
if (lexer.token() == Token.PARTITIONED) {
lexer.nextToken();
accept(Token.BY);
accept(Token.LPAREN);
for (; ; ) {
if (lexer.token() != Token.IDENTIFIER) {
throw new ParserException("expect identifier");
}
SQLColumnDefinition column = this.exprParser.parseColumn();
stmt.addPartitionColumn(column);
if (lexer.isKeepComments() && lexer.hasComment()) {
column.addAfterComment(lexer.readAndResetComments());
}
if (!(lexer.token() == (Token.COMMA))) {
break;
} else {
lexer.nextToken();
if (lexer.isKeepComments() && lexer.hasComment()) {
column.addAfterComment(lexer.readAndResetComments());
}
}
}
accept(Token.RPAREN);
}
if (identifierEquals("LIFECYCLE")) {
lexer.nextToken();
stmt.setLifecycle(this.exprParser.expr());
}
return stmt;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OdpsStatementParser method parseStatementListDialect.
public boolean parseStatementListDialect(List<SQLStatement> statementList) {
if (lexer.token() == Token.FROM) {
SQLStatement stmt = this.parseInsert();
statementList.add(stmt);
return true;
}
if (identifierEquals("ANALYZE")) {
lexer.nextToken();
accept(Token.TABLE);
OdpsAnalyzeTableStatement stmt = new OdpsAnalyzeTableStatement();
SQLName table = this.exprParser.name();
stmt.setTable(table);
if (lexer.token() == Token.PARTITION) {
lexer.nextToken();
accept(Token.LPAREN);
parseAssignItems(stmt.getPartition(), stmt);
accept(Token.RPAREN);
}
accept(Token.COMPUTE);
acceptIdentifier("STATISTICS");
statementList.add(stmt);
return true;
}
if (identifierEquals("ADD")) {
lexer.nextToken();
if (identifierEquals("STATISTIC")) {
lexer.nextToken();
OdpsAddStatisticStatement stmt = new OdpsAddStatisticStatement();
stmt.setTable(this.exprParser.name());
stmt.setStatisticClause(parseStaticClause());
statementList.add(stmt);
return true;
}
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
}
if (identifierEquals("REMOVE")) {
lexer.nextToken();
if (identifierEquals("STATISTIC")) {
lexer.nextToken();
OdpsRemoveStatisticStatement stmt = new OdpsRemoveStatisticStatement();
stmt.setTable(this.exprParser.name());
stmt.setStatisticClause(parseStaticClause());
statementList.add(stmt);
return true;
}
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
}
if (identifierEquals("READ")) {
lexer.nextToken();
OdpsReadStatement stmt = new OdpsReadStatement();
stmt.setTable(this.exprParser.name());
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
this.exprParser.names(stmt.getColumns(), stmt);
accept(Token.RPAREN);
}
if (lexer.token() == Token.PARTITION) {
lexer.nextToken();
accept(Token.LPAREN);
parseAssignItems(stmt.getPartition(), stmt);
accept(Token.RPAREN);
}
if (lexer.token() == Token.LITERAL_INT) {
stmt.setRowCount(this.exprParser.primary());
}
statementList.add(stmt);
return true;
}
if (identifierEquals("LIST")) {
OdpsListStmt stmt = new OdpsListStmt();
lexer.nextToken();
stmt.setObject(this.exprParser.expr());
statementList.add(stmt);
return true;
}
if (lexer.token() == Token.DESC || identifierEquals("DESCRIBE")) {
OdpsDescStmt stmt = parseDescribe();
statementList.add(stmt);
return true;
}
return false;
}
Aggregations