korlov42 commented on code in PR #2455: URL: https://github.com/apache/ignite-3/pull/2455#discussion_r1299894857
########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/trait/Identity.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.sql.engine.trait; + +import java.util.List; +import org.apache.ignite.internal.sql.engine.exec.RowHandler; + +/** + * Destination, which uses a column raw value as a target. + */ +public class Identity<RowT> implements Destination<RowT> { + private final RowHandler<RowT> rowHandler; + private final List<String> nodes; + private final int columnIndex; + + /** + * Constructor. + * + * @param rowHandler Row handler. + * @param columnIndex Column index in a row, which used for affinity calculation. + * @param nodes Names of nodes, which are valid destinations. + */ + public Identity(RowHandler<RowT> rowHandler, int columnIndex, List<String> nodes) { + this.rowHandler = rowHandler; + this.columnIndex = columnIndex; + this.nodes = nodes; + } + + /** {@inheritDoc} */ + @Override + public List<String> targets(RowT row) { + String node = (String) rowHandler.get(columnIndex, row); + + if (nodes.contains(node)) { + return List.of(node); + } + + return List.of(); Review Comment: although it's not specified in javadoc of Destination interfaces, it's expected that call to `targets` will not return an empty collection. I believe it's rather dangerous that some rows are silently dropped on exchange because of misconfiguration or bug in code related to mapping. second, you are calling `nodes.contains` on a List for every row. It doesn't feel right, assuming the size of the cluster may grow over a thousand nodes ########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/IdentityDistributionExecutionTest.java: ########## @@ -0,0 +1,147 @@ +/* + * 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.sql.engine.exec; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import java.util.List; +import java.util.function.Function; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.apache.ignite.internal.schema.NativeTypes; +import org.apache.ignite.internal.sql.engine.AsyncCursor; +import org.apache.ignite.internal.sql.engine.framework.DataProvider; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders.ClusterBuilder; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders.ClusterTableBuilder; +import org.apache.ignite.internal.sql.engine.framework.TestCluster; +import org.apache.ignite.internal.sql.engine.framework.TestNode; +import org.apache.ignite.internal.sql.engine.planner.AbstractPlannerTest; +import org.apache.ignite.internal.sql.engine.prepare.QueryPlan; +import org.apache.ignite.internal.sql.engine.trait.IgniteDistributions; +import org.apache.ignite.internal.sql.engine.util.CursorUtils; +import org.junit.jupiter.api.Test; + +/** + * Execution test for {@link org.apache.ignite.internal.sql.engine.trait.DistributionFunction.IdentityDistribution} function. + */ +public class IdentityDistributionExecutionTest extends AbstractPlannerTest { + + private static final String NODE1_NAME = "node1"; + private static final String NODE2_NAME = "node2"; + private static final String NODE3_NAME = "node3"; + + @Test + public void joinTablesWithSameDistribution() { + TestCluster cluster = createClusterWith(identityTable("TEST_TBL1"), identityTable("TEST_TBL2")); + + cluster.start(); + + String sql = "select * " + + "from TEST_TBL1 t1 " + + "join TEST_TBL2 t2 on t1.id = t2.id"; + + TestNode node = cluster.node(NODE1_NAME); + + QueryPlan queryPlan = node.prepare(sql); + AsyncCursor<List<Object>> cursor = node.executePlan(queryPlan); + + List<List<Object>> allFromCursor = CursorUtils.getAllFromCursor(cursor); + assertThat(allFromCursor.size(), is(3 * 25)); + } + + @Test + public void joinAffinityToIdentity() { + TestCluster cluster = createClusterWith(affinityTable("TEST_TBL1"), identityTable("TEST_TBL2")); + + cluster.start(); + + String sql = "select * " + + "from TEST_TBL1 t1 " + + "join TEST_TBL2 t2 on t1.id = t2.id"; + + TestNode node = cluster.node(NODE1_NAME); + + QueryPlan queryPlan = node.prepare(sql); + AsyncCursor<List<Object>> cursor = node.executePlan(queryPlan); + + List<List<Object>> allFromCursor = CursorUtils.getAllFromCursor(cursor); + assertThat(allFromCursor.size(), is(3 * 5)); + } + + @Test + public void joinIdetityToAffinity() { Review Comment: ```suggestion public void joinIdentityToAffinity() { ``` ########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/IdentityDistributionPlannerTest.java: ########## @@ -0,0 +1,174 @@ +/* + * 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.sql.engine.planner; + +import static org.apache.ignite.internal.sql.engine.trait.IgniteDistributions.single; + +import org.apache.ignite.internal.schema.NativeTypes; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders; +import org.apache.ignite.internal.sql.engine.framework.TestTable; +import org.apache.ignite.internal.sql.engine.rel.IgniteExchange; +import org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan; +import org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin; +import org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Collation; +import org.apache.ignite.internal.sql.engine.schema.IgniteSchema; +import org.apache.ignite.internal.sql.engine.trait.IgniteDistribution; +import org.apache.ignite.internal.sql.engine.trait.IgniteDistributions; +import org.junit.jupiter.api.Test; + +/** + * Test suite to verify join colocation when using + * {@link org.apache.ignite.internal.sql.engine.trait.DistributionFunction.IdentityDistribution} function. + */ +public class IdentityDistributionPlannerTest extends AbstractPlannerTest { Review Comment: should we extend `org.apache.ignite.internal.sql.engine.planner.AbstractAggregatePlannerTest` with a few more cases to cover new distribution? ########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/IdentityDistributionExecutionTest.java: ########## @@ -0,0 +1,147 @@ +/* + * 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.sql.engine.exec; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import java.util.List; +import java.util.function.Function; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.apache.ignite.internal.schema.NativeTypes; +import org.apache.ignite.internal.sql.engine.AsyncCursor; +import org.apache.ignite.internal.sql.engine.framework.DataProvider; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders.ClusterBuilder; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders.ClusterTableBuilder; +import org.apache.ignite.internal.sql.engine.framework.TestCluster; +import org.apache.ignite.internal.sql.engine.framework.TestNode; +import org.apache.ignite.internal.sql.engine.planner.AbstractPlannerTest; +import org.apache.ignite.internal.sql.engine.prepare.QueryPlan; +import org.apache.ignite.internal.sql.engine.trait.IgniteDistributions; +import org.apache.ignite.internal.sql.engine.util.CursorUtils; +import org.junit.jupiter.api.Test; + +/** + * Execution test for {@link org.apache.ignite.internal.sql.engine.trait.DistributionFunction.IdentityDistribution} function. Review Comment: I'm not sure these tests actually test what they are meant to. Neither of queries have Exchange to identity distribution, all data are sent to a single node and then merged together. I mean, there are a lot of tests that resent data with arbitrary distribution to a single place, and then just execute the rest of the query in a colocated mode. It would be nice to see Identity.java distribution function in action -- 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]
