[branch-2.1][fix](expr) Enhance SQL Expression Handling by Introducing printSqlInParens to CompoundPredicate (#39082)
pick #39064
This commit is contained in:
@ -61,11 +61,13 @@ public class CompoundPredicate extends Predicate {
|
||||
if (e2 != null) {
|
||||
children.add(e2);
|
||||
}
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
protected CompoundPredicate(CompoundPredicate other) {
|
||||
super(other);
|
||||
op = other.op;
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -20,8 +20,6 @@ package org.apache.doris.datasource.jdbc.source;
|
||||
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;
|
||||
@ -321,36 +319,6 @@ public class JdbcScanNode extends ExternalScanNode {
|
||||
}
|
||||
|
||||
public static String conjunctExprToString(TOdbcTableType tableType, Expr expr, TableIf tbl) {
|
||||
if (expr instanceof CompoundPredicate) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
CompoundPredicate compoundPredicate = (CompoundPredicate) expr;
|
||||
|
||||
// If the operator is 'NOT', prepend 'NOT' to the start of the string
|
||||
if (compoundPredicate.getOp() == Operator.NOT) {
|
||||
result.append("NOT ");
|
||||
}
|
||||
|
||||
// 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) {
|
||||
ArrayList<Expr> children = expr.getChildren();
|
||||
String filter = children.get(0).toExternalSql(TableType.JDBC_EXTERNAL_TABLE, tbl);
|
||||
@ -367,7 +335,7 @@ public class JdbcScanNode extends ExternalScanNode {
|
||||
return filter;
|
||||
}
|
||||
|
||||
// only for old planner
|
||||
// Only for old planner
|
||||
if (expr.contains(BoolLiteral.class) && "1".equals(expr.getStringValue()) && expr.getChildren().isEmpty()) {
|
||||
return "1 = 1";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user