(improvement)(headless) Delete 'is null' and 'is not null' expressions only in the WHERE clause, and keep them in the HAVING clause (#1680)

This commit is contained in:
lexluo09
2024-09-15 11:05:54 +08:00
committed by GitHub
parent 2086a560b1
commit 70fff17fbe
2 changed files with 32 additions and 3 deletions

View File

@@ -406,9 +406,18 @@ public class SqlRemoveHelper {
SelectDeParser selectDeParser = new SelectDeParser(expressionDeParser, buffer);
expressionDeParser.setSelectVisitor(selectDeParser);
expressionDeParser.setBuffer(buffer);
selectStatement.accept(selectDeParser);
return buffer.toString();
PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
if (plainSelect.getWhere() != null) {
plainSelect.getWhere().accept(expressionDeParser);
}
// Parse the modified WHERE clause back to an Expression
try {
Expression newWhere = CCJSqlParserUtil.parseCondExpression(buffer.toString());
plainSelect.setWhere(newWhere);
} catch (Exception e) {
log.error("parseCondExpression error:{}", buffer, e);
}
return selectStatement.toString();
}
private static boolean isInvalidSelect(Select selectStatement) {