Skip to content

Commit

Permalink
change cast PREDICATES logic to PlanNode
Browse files Browse the repository at this point in the history
  • Loading branch information
liutang123 authored and liutang123 committed Jan 8, 2025
1 parent 65ada34 commit 21eef31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
20 changes: 20 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.doris.analysis.TupleId;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Id;
import org.apache.doris.common.NotImplementedException;
Expand All @@ -59,6 +60,8 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -89,6 +92,7 @@
* its children (= are bound by tupleIds).
*/
public abstract class PlanNode extends TreeNode<PlanNode> implements PlanStats {
private static final Logger LOG = LogManager.getLogger(PlanNode.class);

protected String planNodeName;

Expand Down Expand Up @@ -207,6 +211,7 @@ protected PlanNode(PlanNodeId id, PlanNode node, String planNodeName, Statistica
this.tblRefIds = Lists.newArrayList(node.tblRefIds);
this.nullableTupleIds = Sets.newHashSet(node.nullableTupleIds);
this.conjuncts = Expr.cloneList(node.conjuncts, null);

this.cardinality = -1;
this.compactData = node.compactData;
this.planNodeName = "V" + planNodeName;
Expand Down Expand Up @@ -806,6 +811,21 @@ public void init() throws UserException {}
public void init(Analyzer analyzer) throws UserException {
assignConjuncts(analyzer);
createDefaultSmap(analyzer);
castConjuncts();
}

private void castConjuncts() throws AnalysisException {
for (int i = 0; i < conjuncts.size(); ++i) {
Expr expr = conjuncts.get(i);
if (!expr.getType().isBoolean()) {
try {
conjuncts.set(i, expr.castTo(Type.BOOLEAN));
} catch (AnalysisException e) {
LOG.warn("{} is not boolean and can not be cast to boolean", expr.toSql(), e);
throw new AnalysisException("conjuncts " + expr.toSql() + " is not boolean");
}
}
}
}

/**
Expand Down
13 changes: 0 additions & 13 deletions fe/fe-core/src/main/java/org/apache/doris/planner/SelectNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import org.apache.doris.analysis.Analyzer;
import org.apache.doris.analysis.Expr;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.statistics.StatisticalType;
import org.apache.doris.statistics.StatsRecursiveDerive;
Expand Down Expand Up @@ -68,17 +66,6 @@ protected void toThrift(TPlanNode msg) {
@Override
public void init(Analyzer analyzer) throws UserException {
super.init(analyzer);
for (int i = 0; i < conjuncts.size(); ++i) {
Expr expr = conjuncts.get(i);
if (!expr.getType().isBoolean()) {
try {
conjuncts.set(i, expr.castTo(Type.BOOLEAN));
} catch (AnalysisException e) {
LOG.warn("{} is not boolean and can not be cast to boolean", expr.toSql(), e);
throw new AnalysisException("conjuncts " + expr.toSql() + " is not boolean");
}
}
}
analyzer.markConjunctsAssigned(conjuncts);
computeStats(analyzer);
}
Expand Down

0 comments on commit 21eef31

Please sign in to comment.