alex-plekhanov commented on code in PR #11770:
URL: https://github.com/apache/ignite/pull/11770#discussion_r2718326264


##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/HashJoinPlannerTest.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.planner;
+
+import java.util.List;
+import org.apache.calcite.plan.RelOptPlanner.CannotPlanException;
+import org.apache.calcite.rel.RelCollations;
+import org.apache.calcite.rel.RelFieldCollation;
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.ignite.internal.processors.query.calcite.rel.IgniteHashJoin;
+import org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel;
+import org.apache.ignite.internal.processors.query.calcite.rel.IgniteSort;
+import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema;
+import 
org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static org.apache.calcite.rel.RelFieldCollation.Direction.ASCENDING;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/** */
+public class HashJoinPlannerTest extends AbstractPlannerTest {
+    /** */
+    private static final String[] DISABLED_RULES = {"NestedLoopJoinConverter", 
"CorrelatedNestedLoopJoin", "MergeJoinConverter",
+        "JoinCommuteRule"};
+
+    /** */
+    private static final String[] JOIN_TYPES = {"LEFT", "RIGHT", "INNER", 
"FULL"};
+
+    /** */
+    @Test
+    public void testHashJoinKeepsLeftCollation() throws Exception {
+        TestTable tbl1 = createSimpleTable();
+        TestTable tbl2 = createComplexTable();
+
+        IgniteSchema schema = createSchema(tbl1, tbl2);
+
+        String sql = "select t1.ID, t2.ID1 "
+            + "from TEST_TBL_CMPLX t2 "
+            + "join TEST_TBL t1 on t1.id = t2.id1 "
+            + "order by t2.ID1 NULLS LAST, t2.ID2 NULLS LAST";
+
+        assertPlan(sql, schema, 
nodeOrAnyChild(isInstanceOf(IgniteHashJoin.class))
+            .and(nodeOrAnyChild(isInstanceOf(IgniteSort.class)).negate()), 
DISABLED_RULES);
+    }
+
+    /** */
+    @Test
+    public void testHashJoinErasesRightCollation() throws Exception {
+        TestTable tbl1 = createSimpleTable();
+        TestTable tbl2 = createComplexTable();
+
+        IgniteSchema schema = createSchema(tbl1, tbl2);
+
+        String sql = "select t1.ID, t2.ID1 "
+                + "from TEST_TBL t1 "
+                + "join TEST_TBL_CMPLX t2 on t1.id = t2.id1 "
+                + "order by t2.ID1 NULLS LAST, t2.ID2 NULLS LAST";
+
+        assertPlan(sql, schema, nodeOrAnyChild(isInstanceOf(IgniteSort.class)
+            .and(input(isInstanceOf(IgniteHashJoin.class)))), DISABLED_RULES);
+    }
+
+    /** */
+    @Test
+    public void testHashJoinWinsOnSkewedLeftInput() throws Exception {
+        TestTable smallTbl = createSimpleTable("SMALL_TBL", 1000);
+        TestTable largeTbl = createSimpleTable("LARGE_TBL", 500_000);
+
+        IgniteSchema schema = createSchema(smallTbl, largeTbl);
+
+        assertPlan(
+            "select t1.ID, t1.INT_VAL, t2.ID, t2.INT_VAL from LARGE_TBL t1 
join SMALL_TBL t2 on t1.INT_VAL = t2.INT_VAL",
+            schema,
+            nodeOrAnyChild(isInstanceOf(IgniteHashJoin.class)),
+            "JoinCommuteRule"
+        );
+
+        assertPlan(
+            "select t1.ID, t1.INT_VAL, t2.ID, t2.INT_VAL from SMALL_TBL t1 
join LARGE_TBL t2 on t1.INT_VAL = t2.INT_VAL",
+            schema,
+            nodeOrAnyChild(isInstanceOf(IgniteHashJoin.class).negate()),
+            "JoinCommuteRule"
+        );
+
+        // Merge join can consume less CPU resources.
+        assertPlan(
+            "select t1.ID, t1.INT_VAL, t2.ID, t2.INT_VAL from SMALL_TBL t1 
join LARGE_TBL t2 on t1.ID = t2.ID",
+            schema,
+            nodeOrAnyChild(isInstanceOf(IgniteHashJoin.class).negate()),
+            "JoinCommuteRule"
+        );
+    }
+
+    /** */
+    private static @Nullable IgniteSort sortOnTopOfJoin(IgniteRel root) {

Review Comment:
   Never used



##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/JoinColocationPlannerTest.java:
##########
@@ -143,22 +146,24 @@ public void joinComplexToSimpleAff() throws Exception {
             "from COMPLEX_TBL t1 " +
             "join SIMPLE_TBL t2 on t1.id1 = t2.id";
 
-        RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", 
"CorrelatedNestedLoopJoin");
+        for (String disabledRule : DISABLED_RULES) {
+            RelNode phys = physicalPlan(sql, schema, 
"NestedLoopJoinConverter", "CorrelatedNestedLoopJoin", disabledRule);
 
-        IgniteMergeJoin join = findFirstNode(phys, 
byClass(IgniteMergeJoin.class));
+            AbstractIgniteJoin join = findFirstNode(phys, 
byClass(AbstractIgniteJoin.class));
 
-        String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
+            String invalidPlanMsg = "Invalid plan:\n" + 
RelOptUtil.toString(phys);
 
-        assertThat(invalidPlanMsg, join, notNullValue());
-        assertThat(invalidPlanMsg, join.distribution().function().affinity(), 
is(true));
+            assertThat(invalidPlanMsg, join, notNullValue());
+            assertThat(invalidPlanMsg, 
join.distribution().function().affinity(), is(true));
 
-        List<IgniteExchange> exchanges = findNodes(phys, node -> node 
instanceof IgniteExchange
-            && ((IgniteRel)node).distribution().function().affinity());
+            List<IgniteExchange> exchanges = findNodes(phys, node -> node 
instanceof IgniteExchange
+                && ((IgniteRel)node).distribution().function().affinity());
 
-        assertThat(invalidPlanMsg, exchanges, hasSize(1));
-        assertThat(invalidPlanMsg, exchanges.get(0).getInput(0), 
instanceOf(IgniteIndexScan.class));
-        assertThat(invalidPlanMsg, exchanges.get(0).getInput(0)
-            .getTable().unwrap(TestTable.class), equalTo(complexTbl));
+            assertThat(invalidPlanMsg, exchanges, hasSize(1));
+            assertThat(invalidPlanMsg, exchanges.get(0).getInput(0), 
instanceOf(IgniteIndexScan.class));
+            assertThat(invalidPlanMsg, exchanges.get(0).getInput(0)
+                .getTable().unwrap(TestTable.class), equalTo(complexTbl));
+        }

Review Comment:
   Maybe use the same plan checker as for joinSameTableComplexAff (rewritten 
with `assertPlan`)? 



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

Reply via email to