mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser
This commit is contained in:
@@ -422,15 +422,16 @@ public class SQLUtils {
|
||||
visitor.println();
|
||||
}
|
||||
}
|
||||
{
|
||||
List<String> comments = stmt.getBeforeCommentsDirect();
|
||||
if (comments != null){
|
||||
for(String comment : comments) {
|
||||
visitor.printComment(comment);
|
||||
visitor.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// {
|
||||
// List<String> comments = stmt.getBeforeCommentsDirect();
|
||||
// if (comments != null){
|
||||
// for(String comment : comments) {
|
||||
// visitor.printComment(comment);
|
||||
// visitor.println();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
stmt.accept(visitor);
|
||||
|
||||
if (i == size - 1) {
|
||||
|
||||
@@ -57,6 +57,18 @@ public class OdpsOutputVisitor extends HiveOutputVisitor implements OdpsASTVisit
|
||||
}
|
||||
|
||||
public boolean visit(OdpsCreateTableStatement x) {
|
||||
List<SQLCommentHint> headHints = x.getHeadHintsDirect();
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint hint : headHints) {
|
||||
visit((SQLCommentHint) hint);
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
if (x.hasBeforeComment()) {
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
print0(ucase ? "CREATE " : "create ");
|
||||
|
||||
if (x.isExternal()) {
|
||||
@@ -569,6 +581,18 @@ public class OdpsOutputVisitor extends HiveOutputVisitor implements OdpsASTVisit
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsReadStatement x) {
|
||||
List<SQLCommentHint> headHints = x.getHeadHintsDirect();
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint hint : headHints) {
|
||||
visit((SQLCommentHint) hint);
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
if (x.hasBeforeComment()) {
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
print0(ucase ? "READ " : "read ");
|
||||
x.getTable().accept(this);
|
||||
|
||||
@@ -636,6 +660,18 @@ public class OdpsOutputVisitor extends HiveOutputVisitor implements OdpsASTVisit
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsShowGrantsStmt x) {
|
||||
List<SQLCommentHint> headHints = x.getHeadHintsDirect();
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint hint : headHints) {
|
||||
visit((SQLCommentHint) hint);
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
if (x.hasBeforeComment()) {
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
if (x.isLabel()) {
|
||||
print0(ucase ? "SHOW LABEL GRANTS" : "show label grants");
|
||||
|
||||
@@ -852,6 +888,18 @@ public class OdpsOutputVisitor extends HiveOutputVisitor implements OdpsASTVisit
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsCountStatement x) {
|
||||
List<SQLCommentHint> headHints = x.getHeadHintsDirect();
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint hint : headHints) {
|
||||
visit((SQLCommentHint) hint);
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
if (x.hasBeforeComment()) {
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
print0(ucase ? "COUNT " : "count ");
|
||||
x.getTable().accept(this);
|
||||
|
||||
|
||||
@@ -3078,6 +3078,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
}
|
||||
|
||||
if (x.hasBeforeComment()) {
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
print0(ucase ? "DROP " : "drop ");
|
||||
List<SQLCommentHint> hints = x.getHints();
|
||||
if (hints != null) {
|
||||
@@ -3130,6 +3134,18 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
|
||||
public boolean visit(SQLDropViewStatement x) {
|
||||
List<SQLCommentHint> headHints = x.getHeadHintsDirect();
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint hint : headHints) {
|
||||
visit((SQLCommentHint) hint);
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
if (x.hasBeforeComment()) {
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
print0(ucase ? "DROP VIEW " : "drop view ");
|
||||
|
||||
if (x.isIfExists()) {
|
||||
@@ -3886,6 +3902,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSetStatement x) {
|
||||
if(x.getHeadHintsDirect() != null) {
|
||||
for (SQLCommentHint hint : x.getHeadHintsDirect()) {
|
||||
hint.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (x.hasBeforeComment()) {
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
boolean printSet = x.getAttribute("parser.set") == Boolean.TRUE || !JdbcUtils.isOracleDbType(dbType);
|
||||
if (printSet) {
|
||||
print0(ucase ? "SET " : "set ");
|
||||
@@ -5938,6 +5964,18 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropFunctionStatement x) {
|
||||
List<SQLCommentHint> headHints = x.getHeadHintsDirect();
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint hint : headHints) {
|
||||
visit((SQLCommentHint) hint);
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
if (x.hasBeforeComment()) {
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
if (x.isTemporary()) {
|
||||
print0(ucase ? "DROP TEMPORARY FUNCTION " : "drop temporary function ");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user