improved sql format output

This commit is contained in:
shaojin.wensj
2015-07-11 14:27:29 +08:00
parent 60b7139911
commit b36374f7bf
26 changed files with 612 additions and 35 deletions
@@ -158,6 +158,12 @@ public class SQLSelectParser extends SQLParser {
return queryRest(select);
}
SQLSelectQueryBlock queryBlock = new SQLSelectQueryBlock();
if (lexer.hasComment() && lexer.isKeepComments()) {
queryBlock.addBeforeComment(lexer.commentVal());
}
accept(Token.SELECT);
@@ -165,8 +171,6 @@ public class SQLSelectParser extends SQLParser {
lexer.nextToken();
}
SQLSelectQueryBlock queryBlock = new SQLSelectQueryBlock();
if (lexer.token() == Token.DISTINCT) {
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
lexer.nextToken();
@@ -234,7 +238,15 @@ public class SQLSelectParser extends SQLParser {
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
queryBlock.setWhere(expr());
SQLExpr where = expr();
if (lexer.hasComment() && lexer.isKeepComments() //
&& lexer.token() != Token.INSERT // odps multi-insert
) {
where.addAfterComment(lexer.commentVal());
}
queryBlock.setWhere(where);
}
}
@@ -326,7 +338,13 @@ public class SQLSelectParser extends SQLParser {
parseTableSourceQueryTableExpr(tableReference);
return parseTableSourceRest(tableReference);
SQLTableSource tableSrc = parseTableSourceRest(tableReference);
if (lexer.hasComment() && lexer.isKeepComments()) {
tableSrc.addAfterComment(lexer.commentVal());
}
return tableSrc;
}
private void parseTableSourceQueryTableExpr(SQLExprTableSource tableReference) {