forked from github/dataease
fix: sql参数支持hiving 语法
This commit is contained in:
parent
40d321256d
commit
3fcdd0cf7e
@ -66,6 +66,7 @@ public class SqlparserUtils {
|
||||
}
|
||||
|
||||
if (select.getSelectBody() instanceof PlainSelect) {
|
||||
|
||||
return handlePlainSelect((PlainSelect) select.getSelectBody(), select, dsType);
|
||||
} else {
|
||||
StringBuilder result = new StringBuilder();
|
||||
@ -84,6 +85,7 @@ public class SqlparserUtils {
|
||||
handleSelectItems(plainSelect, dsType);
|
||||
handleFromItems(plainSelect, dsType);
|
||||
handleJoins(plainSelect, dsType);
|
||||
handleHaving(plainSelect);
|
||||
return handleWhere(plainSelect, statementSelect, dsType);
|
||||
}
|
||||
|
||||
@ -175,6 +177,29 @@ public class SqlparserUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static String handleHaving(PlainSelect plainSelect) throws Exception {
|
||||
Expression expr = plainSelect.getHaving();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
BinaryExpression binaryExpression = null;
|
||||
try {
|
||||
binaryExpression = (BinaryExpression) expr;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (binaryExpression != null) {
|
||||
boolean hasSubBinaryExpression = binaryExpression instanceof AndExpression || binaryExpression instanceof OrExpression;
|
||||
if (!hasSubBinaryExpression && !(binaryExpression.getLeftExpression() instanceof BinaryExpression) && !(binaryExpression.getLeftExpression() instanceof InExpression) && (hasVariable(binaryExpression.getLeftExpression().toString()) || hasVariable(binaryExpression.getRightExpression().toString()))) {
|
||||
stringBuilder.append(SubstitutedSql);
|
||||
} else {
|
||||
expr.accept(getExpressionDeParser(stringBuilder));
|
||||
}
|
||||
|
||||
} else {
|
||||
expr.accept(getExpressionDeParser(stringBuilder));
|
||||
}
|
||||
plainSelect.setHaving(CCJSqlParserUtil.parseCondExpression(stringBuilder.toString()));
|
||||
return plainSelect.toString();
|
||||
}
|
||||
|
||||
private static String handleWhere(PlainSelect plainSelect, Select statementSelect, String dsType) throws Exception {
|
||||
Expression expr = plainSelect.getWhere();
|
||||
if (expr == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user