lowka commented on code in PR #1798: URL: https://github.com/apache/ignite-3/pull/1798#discussion_r1146594205
########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/DmlPlannerTest.java: ########## @@ -0,0 +1,121 @@ +/* + * 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 java.util.List; +import java.util.UUID; +import java.util.stream.Stream; +import org.apache.ignite.internal.sql.engine.rel.IgniteExchange; +import org.apache.ignite.internal.sql.engine.rel.IgniteTableModify; +import org.apache.ignite.internal.sql.engine.rel.IgniteTableScan; +import org.apache.ignite.internal.sql.engine.rel.IgniteValues; +import org.apache.ignite.internal.sql.engine.schema.IgniteSchema; +import org.apache.ignite.internal.sql.engine.schema.IgniteTable; +import org.apache.ignite.internal.sql.engine.trait.IgniteDistribution; +import org.apache.ignite.internal.sql.engine.trait.IgniteDistributions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Tests to verify DML plans. + */ +public class DmlPlannerTest extends AbstractPlannerTest { + + /** + * Test for INSERT .. VALUES when table has a single distribution. + */ + @Test + public void testInsertIntoSingleDistributedTable() throws Exception { + IgniteTable test1 = createTable("TEST1", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class); + IgniteSchema schema = createSchema(test1); + + // There should be no exchanges and other operations. + assertPlan("INSERT INTO TEST1 (C1, C2) VALUES(1, 2)", schema, + isInstanceOf(IgniteTableModify.class).and(input(isInstanceOf(IgniteValues.class)))); + } + + /** + * Test for INSERT .. VALUES when table has non single distribution. + */ + @ParameterizedTest + @MethodSource("nonSingleDistributions") + public void testInsert(IgniteDistribution distribution) throws Exception { + IgniteTable test1 = createTable("TEST1", distribution, "C1", Integer.class, "C2", Integer.class); + + IgniteSchema schema = createSchema(test1); + + assertPlan("INSERT INTO TEST1 (C1, C2) VALUES(1, 2)", schema, + nodeOrAnyChild(isInstanceOf(IgniteExchange.class) + .and(e -> e.distribution().equals(IgniteDistributions.single()))) + .and(nodeOrAnyChild(isInstanceOf(IgniteTableModify.class)) + .and(hasChildThat(isInstanceOf(IgniteExchange.class).and(e -> distribution.equals(e.distribution()))))) + ); + } + + private static Stream<IgniteDistribution> nonSingleDistributions() { + return distributions().filter(d -> !IgniteDistributions.single().equals(d)); + } + + /** + * Test for INSERT .. FROM SELECT when tables has different distributions. + */ + @ParameterizedTest + @MethodSource("distributions") + public void testInsertSelectFrom(IgniteDistribution distribution) throws Exception { + IgniteDistribution anotherDistribution = IgniteDistributions.affinity(1, new UUID(1, 0), "0"); + + IgniteTable test1 = createTable("TEST1", distribution, "C1", Integer.class, "C2", Integer.class); + IgniteTable test2 = createTable("TEST2", anotherDistribution, "C1", Integer.class, "C2", Integer.class); + + IgniteSchema schema = createSchema(test1, test2); + + assertPlan("INSERT INTO TEST1 (C1, C2) SELECT C1, C2 FROM TEST2", schema, + nodeOrAnyChild(isInstanceOf(IgniteExchange.class) + .and(e -> e.distribution().equals(IgniteDistributions.single()))) + .and(nodeOrAnyChild(isInstanceOf(IgniteTableModify.class)) + .and(hasChildThat(isInstanceOf(IgniteExchange.class).and(e -> distribution.equals(e.distribution()))))) + ); + } + + /** + * Test for INSERT .. FROM SELECT when tables has the same distribution. + */ + @ParameterizedTest + @MethodSource("distributions") + public void testInsertSelectFromSameDistribution(IgniteDistribution distribution) throws Exception { Review Comment: Added a test case for that. -- 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]
