[fix](jdbc catalog) fix JdbcScanNode NOT CompoundPredicate filter expr handling errors (#28497)

This commit is contained in:
zy-kkk
2023-12-16 12:54:55 +08:00
committed by GitHub
parent 92a4a9770c
commit a3e2c6affe
11 changed files with 129 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import org.apache.doris.analysis.Analyzer;
import org.apache.doris.analysis.BinaryPredicate;
import org.apache.doris.analysis.BoolLiteral;
import org.apache.doris.analysis.CompoundPredicate;
import org.apache.doris.analysis.CompoundPredicate.Operator;
import org.apache.doris.analysis.DateLiteral;
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.ExprSubstitutionMap;
@ -328,13 +329,31 @@ public class JdbcScanNode extends ExternalScanNode {
if (expr instanceof CompoundPredicate) {
StringBuilder result = new StringBuilder();
CompoundPredicate compoundPredicate = (CompoundPredicate) expr;
for (Expr child : compoundPredicate.getChildren()) {
result.append(conjunctExprToString(tableType, child, tbl));
result.append(" ").append(compoundPredicate.getOp().toString()).append(" ");
// If the operator is 'NOT', prepend 'NOT' to the start of the string
if (compoundPredicate.getOp() == Operator.NOT) {
result.append("NOT ");
}
// Remove the last operator
result.setLength(result.length() - compoundPredicate.getOp().toString().length() - 2);
return result.toString();
// Iterate through all children of the CompoundPredicate
for (Expr child : compoundPredicate.getChildren()) {
// Recursively call conjunctExprToString for each child and append to the result
result.append(conjunctExprToString(tableType, child, tbl));
// If the operator is not 'NOT', append the operator after each child expression
if (!(compoundPredicate.getOp() == Operator.NOT)) {
result.append(" ").append(compoundPredicate.getOp().toString()).append(" ");
}
}
// For operators other than 'NOT', remove the extra appended operator at the end
// This is necessary for operators like 'AND' or 'OR' that appear between child expressions
if (!(compoundPredicate.getOp() == Operator.NOT)) {
result.setLength(result.length() - compoundPredicate.getOp().toString().length() - 2);
}
// Return the processed string trimmed of any extra spaces
return result.toString().trim();
}
if (expr.contains(DateLiteral.class) && expr instanceof BinaryPredicate) {