AMashenkov commented on code in PR #6030: URL: https://github.com/apache/ignite-3/pull/6030#discussion_r2145098711
########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/prepare/partitionawareness/PartitionAwarenessMetadataTest.java: ########## @@ -0,0 +1,183 @@ +/* + * 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.prepare.partitionawareness; + +import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; +import org.apache.ignite.internal.catalog.CatalogCommand; +import org.apache.ignite.internal.catalog.commands.DropTableCommand; +import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; +import org.apache.ignite.internal.sql.SqlCommon; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders; +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.prepare.QueryPlan; +import org.apache.ignite.internal.sql.engine.util.Commons; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests forr {@link PartitionAwarenessMetadata} in query plans. + */ +public class PartitionAwarenessMetadataTest extends BaseIgniteAbstractTest { + + private static final String NODE_NAME = "N1"; + + private static final TestCluster CLUSTER = TestBuilders.cluster() + .nodes(NODE_NAME) + .build(); + + private final TestNode node = CLUSTER.node(NODE_NAME); + + @BeforeAll + static void start() { + CLUSTER.start(); + } + + @AfterAll + static void stop() throws Exception { + CLUSTER.stop(); + } + + @AfterEach + void clearCatalog() { + Commons.resetFastQueryOptimizationFlag(); + + int version = CLUSTER.catalogManager().latestCatalogVersion(); + + List<CatalogCommand> commands = new ArrayList<>(); + for (CatalogTableDescriptor table : CLUSTER.catalogManager().catalog(version).tables()) { + commands.add( + DropTableCommand.builder() + .schemaName(SqlCommon.DEFAULT_SCHEMA_NAME) + .tableName(table.name()) + .build() + ); + } + + await(CLUSTER.catalogManager().execute(commands)); + } + + @ParameterizedTest + @ValueSource(strings = { + "SELECT 1", + "KILL QUERY '1'", + "KILL TRANSACTION '1'", + "CREATE TABLE x (a INT, b INT, PRIMARY KEY (a))", + "SELECT * FROM table(system_range(1, 10)) WHERE x = 1", + "SELECT count(*) FROM t WHERE c1=?", + "UPDATE t SET c2=1 WHERE c1=?", + "DELETE FROM t WHERE c1=?", + }) + public void noMetadata(String query) { + node.initSchema("CREATE TABLE t (c1 INT PRIMARY KEY, c2 INT)"); + + QueryPlan plan = node.prepare(query); + PartitionAwarenessMetadata metadata = plan.partitionAwarenessMetadata(); + assertNull(metadata); + } + + @ParameterizedTest + @MethodSource("simpleKeyMetadata") + public void simpleKey(String query, List<Integer> dynamicParams) { + node.initSchema("CREATE TABLE t (c1 INT PRIMARY KEY, c2 INT)"); + + QueryPlan plan = node.prepare(query); + PartitionAwarenessMetadata metadata = plan.partitionAwarenessMetadata(); + + if (dynamicParams == null) { + assertNull(metadata); + } else { + assertNotNull(metadata, "Expected no metadata"); Review Comment: Or maybe ``` public void simpleKey(String query, List<Integer> expected) { .... PartitionAwarenessMetadata actual = metadata == null ? null : IntStream.of(metadata.indexes()).boxed().collect(Collectors.toList()); assertEquals(expected, actual); } ``` Later, you may want to add more complex examples (with hashes or hybrid), and it will be easy to change List->PartitionMetadata in method signature. WDYT? -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org