Skip to content

Commit

Permalink
KE-14627 make constant folding in project configured and upgrade to r…
Browse files Browse the repository at this point in the history
…45 (apache#159)

* KE-14627 make constant folding in project configured and upgrade to r45

* fix

* refactor

Co-authored-by: wangpan <wangpansh@gmail.com>
  • Loading branch information
2 people authored and eventd committed Dec 12, 2022
1 parent 9567597 commit f2ea984
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Expand Up @@ -112,6 +112,8 @@ public interface CalciteConnectionConfig extends ConnectionConfig {
boolean topDownOpt();

/* OVERRIDE POINT */
boolean skipConstantFoldingInProject();

// https://github.com/Kyligence/KAP/issues/17294
<T> T getCustomerValidation(Class<T> validationClass, T defaultValidation);
}
Expand Up @@ -219,6 +219,10 @@ public boolean isSet(CalciteConnectionProperty property) {
.getBoolean();
}

@Override public boolean skipConstantFoldingInProject() {
return false;
}

@Override public boolean lenientOperatorLookup() {
return CalciteConnectionProperty.LENIENT_OPERATOR_LOOKUP.wrap(properties)
.getBoolean();
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.apache.calcite.rel.rules;


import org.apache.calcite.config.CalciteConnectionConfig;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptPredicateList;
import org.apache.calcite.plan.RelOptRuleCall;
Expand Down Expand Up @@ -773,7 +774,14 @@ protected static boolean reduceExpressionsInternal(RelNode rel,
}

final List<RexNode> reducedValues = new ArrayList<>();
executor.reduce(simplify.rexBuilder, constExps2, reducedValues);

CalciteConnectionConfig config =
rel.getCluster().getPlanner().getContext().unwrap(CalciteConnectionConfig.class);
if (config.skipConstantFoldingInProject()) {
reducedValues.addAll(constExps2);
} else {
executor.reduce(simplify.rexBuilder, constExps2, reducedValues);
}

// Use RexNode.digest to judge whether each newly generated RexNode
// is equivalent to the original one.
Expand Down

0 comments on commit f2ea984

Please sign in to comment.