rubenada commented on code in PR #6889:
URL: https://github.com/apache/hive/pull/6889#discussion_r4316761313
##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/TestCBORuleFiredOnlyOnce.java:
##########
@@ -91,6 +102,65 @@ public void testRuleFiredOnlyOnce() {
assertEquals(1, DummyRule.INSTANCE.numberOnMatch);
}
+ @Test
+ public void testHivePreFilteringRuleFiredOnlyOnce() {
+ // Create a program with the rule
+ HepProgramBuilder programBuilder = new HepProgramBuilder();
+ programBuilder.addMatchOrder(HepMatchOrder.DEPTH_FIRST);
+ programBuilder.addRuleInstance(new HivePreFilteringRuleWithCountMatches());
+ HepProgram prog = programBuilder.build();
+
+ // Create a plan
+ final RelNode node = getFilterOnJoinNode();
+ RelMetadataProvider mdProvider = relOptCluster.getMetadataProvider();
+ HepPlanner planner =
+ CalcitePlanner.CalcitePlannerAction.getHepPlanner(node, prog,
mdProvider, false, relOptCluster);
+ planner.setRoot(node);
+ RelNode relNode = planner.findBestExp();
+
+ // Check that the rule changed the original plan, because only then there
is a risk that the rule matches again
+ String plan = RelOptUtil.toString(relNode);
+ assertTrue(
+ "HiveFilter(condition=[>($5, RAND_INTEGER(100))]) expected, but not
found in the following plan: " + plan,
+ plan.contains("HiveFilter(condition=[>($5, RAND_INTEGER(100))])"));
+ assertTrue("HiveFilter(condition=[>($2, 1)]) expected, but not found in
the following plan: " + plan,
+ plan.contains("HiveFilter(condition=[>($2, 1)])"));
+
+ // HivePreFilteringRule adds its result to the registry, so the rule
should not be applied again to its own output
+ assertEquals(1, HivePreFilteringRuleWithCountMatches.countOnMatches);
+ }
+
+ private RelNode getFilterOnJoinNode() {
+ RelNode ts1 = createTS(t1NativeMock, "t1");
+ RelNode ts2 = createTS(t2NativeMock, "t2");
+ RexNode joinCondition = REX_BUILDER.makeCall(SqlStdOperatorTable.EQUALS,
+
REX_BUILDER.makeInputRef(ts1.getRowType().getFieldList().get(0).getType(), 0),
+
REX_BUILDER.makeInputRef(ts2.getRowType().getFieldList().get(0).getType(), 0));
Review Comment:
nit: maybe not relevant for reproducing the issue, but is this join
condition the intended one? It looks `$0=$0` (with a wrong type on the second
one); I guess the 2nd argument should be:
`REX_BUILDER.makeInputRef(ts2.getRowType().getFieldList().get(0).getType(),
ts1.getRowType().getFieldCount())` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]