Vladsz83 commented on code in PR #11770: URL: https://github.com/apache/ignite/pull/11770#discussion_r2726609385
########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/HashJoinExecutionTest.java: ########## @@ -0,0 +1,422 @@ +/* + * 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.exec.rel; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.function.BiPredicate; +import java.util.stream.IntStream; +import java.util.stream.Stream; +import com.google.common.collect.ImmutableList; +import org.apache.calcite.rel.core.JoinRelType; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.calcite.util.ImmutableIntList; +import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext; +import org.apache.ignite.internal.processors.query.calcite.rel.IgniteJoinInfo; +import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory; +import org.apache.ignite.internal.processors.query.calcite.util.TypeUtils; +import org.apache.ignite.internal.util.typedef.F; +import org.jetbrains.annotations.Nullable; +import org.junit.Test; + +import static org.apache.calcite.rel.core.JoinRelType.ANTI; +import static org.apache.calcite.rel.core.JoinRelType.FULL; +import static org.apache.calcite.rel.core.JoinRelType.INNER; +import static org.apache.calcite.rel.core.JoinRelType.LEFT; +import static org.apache.calcite.rel.core.JoinRelType.RIGHT; +import static org.apache.calcite.rel.core.JoinRelType.SEMI; + +/** */ +public class HashJoinExecutionTest extends AbstractExecutionTest { + /** */ + @Test + public void testHashJoinRewind() { + ExecutionContext<Object[]> ctx = executionContext(); + + RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), Integer.class, String.class); + RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), Integer.class, String.class, Integer.class); + + ScanNode<Object[]> deps = new ScanNode<>( + ctx, + rightType, + Arrays.asList( + new Object[] {1, "Core"}, + new Object[] {2, "SQL"}, + new Object[] {3, "QA"} + )); + + ScanNode<Object[]> persons = new ScanNode<>( + ctx, + leftType, + Arrays.asList( + new Object[] {0, "Igor", 1}, + new Object[] {1, "Roman", 2}, + new Object[] {2, "Ivan", 5}, + new Object[] {3, "Alexey", 1} + )); + + HashJoinNode<Object[]> join = createJoinNode(ctx, LEFT, leftType, rightType, null); + + join.register(F.asList(persons, deps)); + + ProjectNode<Object[]> project = new ProjectNode<>(ctx, join.rowType(), r -> new Object[] {r[2], r[3], r[1]}); + project.register(join); + + RootRewindable<Object[]> node = new RootRewindable<>(ctx, project.rowType()); + + node.register(project); + + assert node.hasNext(); + + ArrayList<Object[]> rows = new ArrayList<>(); + + while (node.hasNext()) + rows.add(node.next()); + + Object[][] expected = { + {1, 1, "Igor"}, + {1, 1, "Alexey"}, + {2, 2, "Roman"}, + {5, null, "Ivan"}, + }; + + checkResults(expected, rows); + + node.rewind(); + + assert node.hasNext(); + + rows.clear(); + + while (node.hasNext()) + rows.add(node.next()); + + checkResults(expected, rows); + } + + /** */ + @Test + public void testEquiJoinWithDifferentBufferSize() { + for (JoinRelType joinType : F.asList(INNER, LEFT, RIGHT, FULL, SEMI, ANTI)) { + validateEquiJoin(joinType, 0, 0); + validateEquiJoin(joinType, 0, 1); + validateEquiJoin(joinType, 0, 10); + validateEquiJoin(joinType, 1, 0); + validateEquiJoin(joinType, 1, 1); + validateEquiJoin(joinType, 1, 10); + validateEquiJoin(joinType, 10, 0); + validateEquiJoin(joinType, 10, 1); + validateEquiJoin(joinType, 10, 10); + + int testSize = IN_BUFFER_SIZE; + + validateEquiJoin(joinType, 0, testSize - 1); + validateEquiJoin(joinType, 0, testSize); + validateEquiJoin(joinType, 0, testSize + 1); + + validateEquiJoin(joinType, testSize - 1, 0); + validateEquiJoin(joinType, testSize - 1, testSize - 1); + validateEquiJoin(joinType, testSize - 1, testSize); + validateEquiJoin(joinType, testSize - 1, testSize + 1); + + validateEquiJoin(joinType, testSize, 0); + validateEquiJoin(joinType, testSize, testSize - 1); + validateEquiJoin(joinType, testSize, testSize); + validateEquiJoin(joinType, testSize, testSize + 1); + + validateEquiJoin(joinType, testSize + 1, 0); + validateEquiJoin(joinType, testSize + 1, testSize - 1); + validateEquiJoin(joinType, testSize + 1, testSize); + validateEquiJoin(joinType, testSize + 1, testSize + 1); + + validateEquiJoin(joinType, 2 * testSize, 0); + validateEquiJoin(joinType, 0, 2 * testSize); + validateEquiJoin(joinType, 2 * testSize, 2 * testSize); + } + } + + /** */ + @Test + public void testNonEquiJoinWithDifferentBufferSize() { + JoinRelType joinType = INNER; + + validateNonEquiJoin(joinType, 0, 0); + validateNonEquiJoin(joinType, 0, 1); + validateNonEquiJoin(joinType, 0, 10); + validateNonEquiJoin(joinType, 1, 0); + validateNonEquiJoin(joinType, 1, 1); + validateNonEquiJoin(joinType, 1, 10); + validateNonEquiJoin(joinType, 10, 0); + validateNonEquiJoin(joinType, 10, 1); + validateNonEquiJoin(joinType, 10, 10); + + int testSize = IN_BUFFER_SIZE; + + validateNonEquiJoin(joinType, 0, testSize - 1); + validateNonEquiJoin(joinType, 0, testSize); + validateNonEquiJoin(joinType, 0, testSize + 1); + + validateNonEquiJoin(joinType, testSize - 1, 0); + validateNonEquiJoin(joinType, testSize - 1, testSize - 1); + validateNonEquiJoin(joinType, testSize - 1, testSize); + validateNonEquiJoin(joinType, testSize - 1, testSize + 1); + + validateNonEquiJoin(joinType, testSize, 0); + validateNonEquiJoin(joinType, testSize, testSize - 1); + validateNonEquiJoin(joinType, testSize, testSize); + validateNonEquiJoin(joinType, testSize, testSize + 1); + + validateNonEquiJoin(joinType, testSize + 1, 0); + validateNonEquiJoin(joinType, testSize + 1, testSize - 1); + validateNonEquiJoin(joinType, testSize + 1, testSize); + validateNonEquiJoin(joinType, testSize + 1, testSize + 1); + + validateNonEquiJoin(joinType, 2 * testSize, 0); + validateNonEquiJoin(joinType, 0, 2 * testSize); + validateNonEquiJoin(joinType, 2 * testSize, 2 * testSize); + } + + /** */ + @Test + public void testInnerJoinWithPostFiltration() { + doTestJoinWithPostFiltration(INNER, new Object[][]{{3, "Alexey", 1, 1, "Core"}}); + } + + /** */ + @Test + public void testLeftJoinWithPostFiltration() { + Object[][] expected = new Object[][]{ Review Comment: There is a condition `((CharSequence)l[1]).length() > 4;`. However, Left is reverted for now. -- 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]
