mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed sql parser aggregate distinct output
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ public class OracleAggregateExpr extends SQLAggregateExpr implements Serializabl
|
||||
super(methodName);
|
||||
}
|
||||
|
||||
public OracleAggregateExpr(String methodName, int option){
|
||||
public OracleAggregateExpr(String methodName, Option option){
|
||||
super(methodName, option);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
@@ -524,9 +525,11 @@ public class OracleExprParser extends SQLExprParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected OracleAggregateExpr parseAggregateExpr(String method_name) {
|
||||
protected OracleAggregateExpr parseAggregateExpr(String methodName) {
|
||||
boolean unique = false;
|
||||
|
||||
methodName = methodName.toUpperCase();
|
||||
|
||||
if (lexer.token() == Token.UNIQUE) {
|
||||
lexer.nextToken();
|
||||
unique = true;
|
||||
@@ -534,13 +537,13 @@ public class OracleExprParser extends SQLExprParser {
|
||||
|
||||
OracleAggregateExpr aggregateExpr;
|
||||
if (lexer.token() == (Token.ALL)) {
|
||||
aggregateExpr = new OracleAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new OracleAggregateExpr(methodName, SQLAggregateExpr.Option.ALL);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == (Token.DISTINCT)) {
|
||||
aggregateExpr = new OracleAggregateExpr(method_name, 0);
|
||||
aggregateExpr = new OracleAggregateExpr(methodName, SQLAggregateExpr.Option.DISTINCT);
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
aggregateExpr = new OracleAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new OracleAggregateExpr(methodName);
|
||||
}
|
||||
aggregateExpr.setUnique(unique);
|
||||
exprList(aggregateExpr.getArguments());
|
||||
|
||||
@@ -211,6 +211,12 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
public boolean visit(OracleAggregateExpr expr) {
|
||||
print(expr.getMethodName());
|
||||
print("(");
|
||||
|
||||
if (expr.getOption() != null) {
|
||||
print(expr.getOption().toString());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
if (expr.isUnique()) {
|
||||
print("UNIQUE ");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class PGAggregateExpr extends SQLAggregateExpr implements PGSQLObject {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public PGAggregateExpr(String methodName, int option) {
|
||||
public PGAggregateExpr(String methodName, Option option) {
|
||||
super(methodName, option);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,16 +19,18 @@ public class PGExprParser extends SQLExprParser{
|
||||
super(lexer);
|
||||
}
|
||||
|
||||
protected SQLAggregateExpr parseAggregateExpr(String method_name) throws ParserException {
|
||||
protected SQLAggregateExpr parseAggregateExpr(String methodName) throws ParserException {
|
||||
methodName = methodName.toUpperCase();
|
||||
|
||||
PGAggregateExpr aggregateExpr;
|
||||
if (lexer.token() == Token.ALL) {
|
||||
aggregateExpr = new PGAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new PGAggregateExpr(methodName, SQLAggregateExpr.Option.ALL);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.DISTINCT) {
|
||||
aggregateExpr = new PGAggregateExpr(method_name, 0);
|
||||
aggregateExpr = new PGAggregateExpr(methodName, SQLAggregateExpr.Option.DISTINCT);
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
aggregateExpr = new PGAggregateExpr(method_name, 1);
|
||||
aggregateExpr = new PGAggregateExpr(methodName);
|
||||
}
|
||||
|
||||
exprList(aggregateExpr.getArguments());
|
||||
|
||||
@@ -433,12 +433,21 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
@Override
|
||||
public boolean visit(PGAggregateExpr x) {
|
||||
print(x.getMethodName());
|
||||
|
||||
print("(");
|
||||
|
||||
if (x.getOption() != null) {
|
||||
print(x.getOption().toString());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
printAndAccept(x.getArguments(), ", ");
|
||||
print(")");
|
||||
|
||||
if (x.getOver() != null) {
|
||||
x.getOver().accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user