thomasrebele commented on code in PR #6360:
URL: https://github.com/apache/hive/pull/6360#discussion_r2965230306


##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static 
org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+  TestRuleHelper.PlanFixture fixture() {
+    RelOptPlanner planner = 
buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+    planner.setExecutor(new HiveRexExecutorImpl());
+    return new TestRuleHelper.PlanFixture(planner)
+            .registerTable("t1", T1Record.class)
+            .registerTable("t2", T2Record.class);
+  }
+
+
+  @Test
+  public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {

Review Comment:
   `RelOptUtil.toString(decorrelatedPlan)` and `RelOptUtil.toString(base)` 
appear repeatedly. Assigning them to a variable saves a few computations.



##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static 
org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+  TestRuleHelper.PlanFixture fixture() {
+    RelOptPlanner planner = 
buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+    planner.setExecutor(new HiveRexExecutorImpl());
+    return new TestRuleHelper.PlanFixture(planner)
+            .registerTable("t1", T1Record.class)
+            .registerTable("t2", T2Record.class);
+  }
+
+
+  @Test
+  public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {
+    RelBuilder relBuilder = fixture().createRelBuilder();
+    Holder<RexCorrelVariable> v = Holder.empty();
+    RelNode base = relBuilder
+            .scan("t1")
+            .empty()
+            .scan("t1")
+            .variable(v)
+            .scan("t2")
+            .filter(relBuilder.call(SqlStdOperatorTable.EQUALS, 
relBuilder.getRexBuilder().makeFieldAccess(v.get(), 0), relBuilder.literal(10)))
+            .correlate(JoinRelType.SEMI, v.get().id, relBuilder.field(2, 0, 
"t1id"))
+            .union(false)
+            .build();
+
+    Assert.assertTrue("Plan before decorrelation does not contain correlate: 
\n" + RelOptUtil.toString(base),

Review Comment:
   I was a bit confused by the messages, until I realized that they apply only 
in the case of an assertion error.
   
   How about reformulating them to 
   * "Plan before decorrelation must contain a Correlate node"
   * "Plan before decorrelation must contain a Values node"
   * "Plan after decorrelation may not contain a Correlate node"
   * "Plan after decorrelation must still contain a Values node"



##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveRelDecorrelator.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.Holder;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRexExecutorImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static 
org.apache.hadoop.hive.ql.optimizer.calcite.rules.TestRuleHelper.buildPlanner;
+import static org.junit.Assert.*;
+
+public class TestHiveRelDecorrelator {
+
+  TestRuleHelper.PlanFixture fixture() {
+    RelOptPlanner planner = 
buildPlanner(Collections.singletonList(HiveAntiSemiJoinRule.INSTANCE));
+    planner.setExecutor(new HiveRexExecutorImpl());
+    return new TestRuleHelper.PlanFixture(planner)
+            .registerTable("t1", T1Record.class)
+            .registerTable("t2", T2Record.class);
+  }
+
+
+  @Test
+  public void testDecorrelateCorrelateIsRemovedWhenPlanHasEmptyValues() {
+    RelBuilder relBuilder = fixture().createRelBuilder();
+    Holder<RexCorrelVariable> v = Holder.empty();
+    RelNode base = relBuilder
+            .scan("t1")
+            .empty()
+            .scan("t1")
+            .variable(v)
+            .scan("t2")
+            .filter(relBuilder.call(SqlStdOperatorTable.EQUALS, 
relBuilder.getRexBuilder().makeFieldAccess(v.get(), 0), relBuilder.literal(10)))
+            .correlate(JoinRelType.SEMI, v.get().id, relBuilder.field(2, 0, 
"t1id"))
+            .union(false)
+            .build();
+
+    Assert.assertTrue("Plan before decorrelation does not contain correlate: 
\n" + RelOptUtil.toString(base),
+            RelOptUtil.toString(base).contains("Correlate"));
+    Assert.assertTrue("Plan before decorrelation does not contain Values: \n" 
+ RelOptUtil.toString(base),
+            RelOptUtil.toString(base).contains("Values"));
+
+    RelNode decorrelatedPlan = HiveRelDecorrelator.decorrelateQuery(base);
+
+    Assert.assertFalse("Plan after decorrelation still has correlate: \n" + 
RelOptUtil.toString(decorrelatedPlan),
+            RelOptUtil.toString(decorrelatedPlan).contains("Correlate"));
+    Assert.assertTrue("Plan after decorrelation does not contain Values: \n" + 
RelOptUtil.toString(decorrelatedPlan),

Review Comment:
   I would recommend to dump the before and after plan into a comment. The 
plans are reasonably small and they help to understand what's going on.



-- 
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]

Reply via email to