use of com.alibaba.druid.sql.dialect.blink.ast.BlinkCreateTableStatement in project druid by alibaba.
the class BlinkOutputVisitor method printTableElements.
protected void printTableElements(List<SQLTableElement> tableElementList) {
int size = tableElementList.size();
if (size == 0) {
return;
}
BlinkCreateTableStatement stmt = (BlinkCreateTableStatement) tableElementList.get(0).getParent();
print0(" (");
this.indentCount++;
println();
for (int i = 0; i < size; ++i) {
SQLTableElement element = tableElementList.get(i);
element.accept(this);
if (i != size - 1) {
print(',');
}
if (this.isPrettyFormat() && element.hasAfterComment()) {
print(' ');
printlnComment(element.getAfterCommentsDirect());
}
if (i != size - 1) {
println();
}
}
if (stmt.getPeriodFor() != null) {
print(',');
println();
print0(ucase ? "PERIODĀ FOR " : "periodĀ for ");
stmt.getPeriodFor().accept(this);
}
this.indentCount--;
println();
print(')');
}
use of com.alibaba.druid.sql.dialect.blink.ast.BlinkCreateTableStatement in project druid by alibaba.
the class BlinkCreateTableParser method parseCreateTable.
public SQLCreateTableStatement parseCreateTable(boolean acceptCreate) {
BlinkCreateTableStatement stmt = new BlinkCreateTableStatement();
if (acceptCreate) {
accept(Token.CREATE);
}
if (lexer.identifierEquals(FnvHash.Constants.EXTERNAL)) {
lexer.nextToken();
stmt.setExternal(true);
}
accept(Token.TABLE);
if (lexer.token() == Token.IF || lexer.identifierEquals("IF")) {
lexer.nextToken();
accept(Token.NOT);
accept(Token.EXISTS);
stmt.setIfNotExiists(true);
}
stmt.setName(this.exprParser.name());
accept(Token.LPAREN);
if (lexer.isKeepComments() && lexer.hasComment()) {
stmt.addBodyBeforeComment(lexer.readAndResetComments());
}
for_: for (; ; ) {
SQLColumnDefinition column = null;
switch(lexer.token()) {
case IDENTIFIER:
case KEY:
column = this.exprParser.parseColumn();
column.setParent(stmt);
stmt.getTableElementList().add(column);
break;
case PRIMARY:
SQLTableConstraint constraint = this.parseConstraint();
constraint.setParent(stmt);
stmt.getTableElementList().add(constraint);
break;
case PERIOD:
lexer.nextToken();
accept(Token.FOR);
SQLExpr periodFor = this.exprParser.primary();
stmt.setPeriodFor(periodFor);
break for_;
default:
throw new ParserException("expect identifier. " + lexer.info());
}
if (lexer.isKeepComments() && lexer.hasComment() && column != null) {
column.addAfterComment(lexer.readAndResetComments());
}
if (!(lexer.token() == (Token.COMMA))) {
break;
} else {
lexer.nextToken();
if (lexer.isKeepComments() && lexer.hasComment() && column != null) {
column.addAfterComment(lexer.readAndResetComments());
}
}
}
accept(Token.RPAREN);
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
stmt.setComment(this.exprParser.primary());
}
if (stmt.getClusteredBy().size() > 0 || stmt.getSortedBy().size() > 0) {
accept(Token.INTO);
if (lexer.token() == Token.LITERAL_INT) {
stmt.setBuckets(lexer.integerValue().intValue());
lexer.nextToken();
} else {
throw new ParserException("into buckets must be integer. " + lexer.info());
}
acceptIdentifier("BUCKETS");
}
if (lexer.token() == Token.WITH) {
lexer.nextToken();
accept(Token.LPAREN);
parseAssignItems(stmt.getTableOptions(), stmt, true);
accept(Token.RPAREN);
}
return stmt;
}
Aggregations