This is an automated email from the ASF dual-hosted git repository. amashenkov pushed a commit to branch sql-virtual-column-poc in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit db732f974aa2f963e66a5e2f879cd57fb44a8d06 Author: amashenkov <[email protected]> AuthorDate: Thu Jun 13 18:32:00 2024 +0300 Add tests. --- .../internal/sql/engine/ItCreateTableDdlTest.java | 89 +++++++++++++++++++++- .../internal/sql/engine/planner/PlannerTest.java | 14 ++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java index 4d3261235d..82359cc374 100644 --- a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java +++ b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java @@ -30,6 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; import java.util.Objects; +import java.util.concurrent.ExecutionException; import java.util.stream.Stream; import org.apache.ignite.internal.app.IgniteImpl; import org.apache.ignite.internal.catalog.Catalog; @@ -38,10 +39,15 @@ import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogZoneDescriptor; import org.apache.ignite.internal.schema.Column; import org.apache.ignite.internal.sql.BaseSqlIntegrationTest; +import org.apache.ignite.internal.table.partition.HashPartition; import org.apache.ignite.sql.SqlException; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; +import org.apache.ignite.table.partition.PartitionManager; import org.apache.ignite.tx.Transaction; import org.apache.ignite.tx.TransactionOptions; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -178,7 +184,7 @@ public class ItCreateTableDdlTest extends BaseSqlIntegrationTest { } /** - * Check implicit colocation columns configuration (defined by PK).. + * Check implicit colocation columns configuration (defined by PK). */ @Test public void implicitColocationColumns() { @@ -191,6 +197,87 @@ public class ItCreateTableDdlTest extends BaseSqlIntegrationTest { assertEquals("ID0", colocationColumns.get(1).name()); } + // TODO: fix or create a ticket + @Disabled + @Test + public void reservedColumnNames() { + assertThrowsSqlException( + STMT_VALIDATION_ERR, + "Failed to validate query. Column '__P_KEY' specified more that once", + () -> sql("CREATE TABLE T0(__P_KEY INT PRIMARY KEY, VAL INT)") + ); + + assertThrowsSqlException( + STMT_VALIDATION_ERR, + "Failed to validate query. Column '__PART' specified more that once", + () -> sql("CREATE TABLE T0(__PART INT PRIMARY KEY, VAL INT)") + ); + + sql("CREATE TABLE T0(ID0 INT PRIMARY KEY, VAL INT)"); + + assertThrowsSqlException( + STMT_VALIDATION_ERR, + "Failed to validate query. Column '__P_KEY' specified more that once", + () -> sql("ALTER TABLE T0 ADD COLUMN __P_KEY INT") + ); + + assertThrowsSqlException( + STMT_VALIDATION_ERR, + "Failed to validate query. Column '__PART' specified more that once", + () -> sql("ALTER TABLE T0 ADD COLUMN __PART INT") + ); + } + + /** + * Check implicit partition column configuration (defined by PK).. + */ + @Test + public void implicitPartitionColumn() throws ExecutionException, InterruptedException { + sql("CREATE TABLE T0(ID BIGINT PRIMARY KEY, VAL VARCHAR)"); + + List<Column> columns = unwrapTableViewInternal(table("T0")).schemaView().lastKnownSchema().columns(); + + assertEquals(2, columns.size()); + assertEquals("ID", columns.get(0).name()); + assertEquals("VAL", columns.get(1).name()); + + sql("insert into t0 (ID, VAL) values (101, 'v1')"); + sql("insert into t0 values (102, 'v2')"); + + Tuple key1 = Tuple.create().set("id", 101L); + Tuple key2 = Tuple.create().set("id", 102L); + + Table table = CLUSTER.node(0).tables().table("T0"); + assertEquals(Tuple.create().set("val", "v1"), table.keyValueView().get(null, key1)); + assertEquals(Tuple.create().set("val", "v2"), table.keyValueView().get(null, key2)); + + assertQuery("SELECT id, val FROM t0") + .returns(101L, "v1") + .returns(102L, "v2") + .check(); + + assertQuery("SELECT * FROM t0") + .returns(101L, "v1") + .returns(102L, "v2") + .check(); + + PartitionManager partitionManager = table.partitionManager(); + int key1Part = ((HashPartition)partitionManager.partitionAsync(key1).get()).partitionId(); + int key2Part = ((HashPartition)partitionManager.partitionAsync(key2).get()).partitionId(); + + assert key1Part != key2Part : key1Part; + + assertQuery("SELECT __part FROM t0") + .returns(key1Part) + .returns(key2Part) + .check(); + + assertQuery("SELECT __part, id, val FROM t0") + .returns(key1Part, 101L, "v1") + .returns(key2Part, 102L, "v2") + .check(); + } + /** * Check explicit colocation columns configuration. */ diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PlannerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PlannerTest.java index ce5fbf507f..f80185f0cf 100644 --- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PlannerTest.java +++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PlannerTest.java @@ -91,6 +91,20 @@ public class PlannerTest extends AbstractPlannerTest { } } + @Test + public void test() throws Exception { + IgniteSchema publicSchema = createSchema(TestBuilders.table() + .name("TEST") + .addColumn("ID", NativeTypes.INT32) + .addColumn("VAL", NativeTypes.STRING) + .distribution(IgniteDistributions.single()) + .build()); + + String sql = "SELECT __part from test"; + + assertPlan(sql, publicSchema, nodeOrAnyChild(isInstanceOf(TableScan.class))); + } + @Test public void testMergeFilters() throws Exception { IgniteSchema publicSchema = createSchema(TestBuilders.table()
