mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved odps sql formatter
This commit is contained in:
@@ -356,13 +356,30 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
for (int i = groupList.size() - 1; i >= 0; --i) {
|
||||
SQLExpr item = groupList.get(i);
|
||||
|
||||
if (relational) {
|
||||
if (isPrettyFormat() && item.hasBeforeComment()) {
|
||||
printlnComments(item.getBeforeCommentsDirect());
|
||||
}
|
||||
}
|
||||
|
||||
if (isPrettyFormat() && item.hasBeforeComment()) {
|
||||
printlnComments(item.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
visitBinaryLeft(item, x.getOperator());
|
||||
|
||||
if (isPrettyFormat() && item.hasAfterComment()) {
|
||||
print(' ');
|
||||
printComment(item.getAfterCommentsDirect(), "\n");
|
||||
}
|
||||
|
||||
if (i != groupList.size() - 1 && isPrettyFormat() && item.getParent().hasAfterComment()) {
|
||||
print(' ');
|
||||
printComment(item.getParent().getAfterCommentsDirect(), "\n");
|
||||
}
|
||||
|
||||
if (relational) {
|
||||
if (isPrettyFormat() && item.hasAfterComment()) {
|
||||
print(' ');
|
||||
printComment(item.getAfterCommentsDirect(), "\n");
|
||||
}
|
||||
println();
|
||||
} else {
|
||||
print(" ");
|
||||
@@ -381,6 +398,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
private void visitorBinaryRight(SQLBinaryOpExpr x) {
|
||||
if (isPrettyFormat() && x.getRight().hasBeforeComment()) {
|
||||
printlnComments(x.getRight().getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
if (x.getRight() instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr right = (SQLBinaryOpExpr) x.getRight();
|
||||
boolean rightRational = right.getOperator() == SQLBinaryOperator.BooleanAnd
|
||||
@@ -404,6 +425,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
} else {
|
||||
x.getRight().accept(this);
|
||||
}
|
||||
|
||||
if (x.getRight().hasAfterComment() && isPrettyFormat()) {
|
||||
print(' ');
|
||||
printlnComments(x.getRight().getAfterCommentsDirect());
|
||||
}
|
||||
}
|
||||
|
||||
private void visitBinaryLeft(SQLExpr left, SQLBinaryOperator op) {
|
||||
@@ -2140,9 +2166,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean visit(SQLUnionQueryTableSource x) {
|
||||
print("(");
|
||||
incrementIndent();
|
||||
x.getUnion().accept(this);
|
||||
println();
|
||||
x.getUnion().accept(this);
|
||||
decrementIndent();
|
||||
println();
|
||||
print(")");
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
@@ -2217,6 +2244,15 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
}
|
||||
|
||||
protected void printlnComments(List<String> comments) {
|
||||
if (comments != null) {
|
||||
for (int i = 0; i < comments.size(); ++i) {
|
||||
String comment = comments.get(i);
|
||||
println(comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterViewRenameStatement x) {
|
||||
print("ALTER VIEW ");
|
||||
|
||||
Reference in New Issue
Block a user