Skip to content

Commit

Permalink
Retry simplify until a RexNode is simplified completely, upto a max of 5
Browse files Browse the repository at this point in the history
tries.

This can be removed after upgrading to Calcite 1.38
https://issues.apache.org/jira/browse/CALCITE-6453
  • Loading branch information
soumyakanti3578 committed Jul 23, 2024
1 parent da97bce commit 298d298
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public static ImmutableList<RexNode> getPredsNotPushedAlready(Set<String> predic
Map<String,RexNode> stringToRexNode = Maps.newLinkedHashMap();
RexSimplify simplify = new RexSimplify(inp.getCluster().getRexBuilder(), RelOptPredicateList.EMPTY, RexUtil.EXECUTOR);
for (RexNode r : predsToPushDown) {
r = simplify.simplify(r);
r = simplify(simplify, r);
String rexNodeString = r.toString();
if (predicatesToExclude.add(rexNodeString)) {
stringToRexNode.put(rexNodeString, r);
Expand All @@ -687,6 +687,20 @@ public static ImmutableList<RexNode> getPredsNotPushedAlready(Set<String> predic
predicatesToExclude.addAll(predicatesInSubtree);
return newConjuncts.build();
}

private static RexNode simplify(RexSimplify simplifier, RexNode node) {
RexNode result = node;
int maxTries = 5;
for (int i = 0; i < maxTries; i++) {
RexNode simplified = simplifier.simplify(result);
if (simplified.equals(result)) {
break;
}
result = simplified;
}

return result;
}

public static RexNode getTypeSafePred(RelOptCluster cluster, RexNode rex, RelDataType rType) {
RexNode typeSafeRex = rex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set hive.support.concurrency=true;
set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
set hive.strict.checks.cartesian.product=false;
set hive.stats.fetch.column.stats=true;
set hive.cbo.rule.exclusion.regex=HivePreFilteringRule;

create database if not exists mydb_e10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ POSTHOOK: Input: mydb_e10@d4_tab_e10
POSTHOOK: Input: mydb_e10@f2_tab_e10
POSTHOOK: Input: mydb_e10@f_tab_e10
#### A masked pattern was here ####
Excluded rules: HivePreFilteringRule

CBO PLAN:
HiveProject(c1=[$11], c5=[$13], c6=[$14], c3=[$1], c4=[$2], c51=[$3], c61=[$4], c7=[$5], c8=[$6], c9=[$7], c10=[$8], c11=[$9], c12=[$19], c41=[$21], c52=[$22], c2=[$18])
HiveJoin(condition=[=($11, $20)], joinType=[inner], algorithm=[none], cost=[not available])
Expand Down

0 comments on commit 298d298

Please sign in to comment.