This is an automated email from the ASF dual-hosted git repository. amashenkov pushed a commit to branch ignite-19942 in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit 97dbfdc4f32259c7583e89ba3e9e8b2e1fd6d004 Author: amashenkov <andrey.mashen...@gmail.com> AuthorDate: Fri Jul 7 15:40:08 2023 +0300 Mirror Table changes from Config to Catalog. --- .../internal/catalog/commands/CatalogUtils.java | 69 ++++++- .../internal/catalog/commands/ColumnParams.java | 6 +- .../internal/catalog/CatalogManagerSelfTest.java | 2 +- .../storage/ItRebalanceDistributedTest.java | 32 ++-- .../inmemory/ItRaftStorageVolatilityTest.java | 12 +- .../raftsnapshot/ItTableRaftSnapshotsTest.java | 2 +- .../runner/app/ItIgniteNodeRestartTest.java | 5 +- .../runner/app/ItSchemaChangeKvViewTest.java | 2 + .../runner/app/ItSchemaChangeTableViewTest.java | 1 + .../runner/app/ItTableApiContractTest.java | 124 ++++++------ .../internal/runner/app/ItTablesApiTest.java | 56 +++--- .../runner/app/PlatformTestNodeRunner.java | 18 +- .../ignite/internal/sql/api/ItCommonApiTest.java | 6 +- .../internal/sql/api/ItSqlAsynchronousApiTest.java | 22 +-- .../internal/sql/api/ItSqlSynchronousApiTest.java | 24 +-- .../internal/sql/engine/ItCreateTableDdlTest.java | 30 +-- .../ignite/internal/table/ItRoReadsTest.java | 24 ++- .../org/apache/ignite/internal/app/IgniteImpl.java | 1 + modules/schema/build.gradle | 1 + .../internal/schema/CatalogDescriptorUtils.java | 111 +++++++++++ .../testutils/SchemaToCatalogParamsConverter.java | 208 +++++++++++++++++++++ .../sql/engine/exec/ddl/DdlCommandHandler.java | 2 +- .../engine/exec/ddl/DdlCommandHandlerWrapper.java | 42 ++--- .../exec/ddl/DdlToCatalogCommandConverter.java | 3 + .../sql/engine/exec/MockedStructuresTest.java | 8 + .../internal/table/distributed/TableManager.java | 204 +++++++++++++++++++- .../table/distributed/TableManagerTest.java | 72 ++++--- 27 files changed, 812 insertions(+), 275 deletions(-) diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java index 7823b09d47..d157cbaba2 100644 --- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java +++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java @@ -38,6 +38,31 @@ import org.apache.ignite.sql.ColumnType; * Catalog utils. */ public class CatalogUtils { + /** + * Default TIMESTAMP type precision: microseconds. + * + * <p>SQL`16 part 2 section 6.1 syntax rule 36 + */ + public static final int DEFAULT_TIMESTAMP_PRECISION = 6; + /** + * Default TIME type precision: seconds. + * + * <p>SQL`16 part 2 section 6.1 syntax rule 36 + */ + public static final int DEFAULT_TIME_PRECISION = 0; + /** + * Default DECIMAL precision is implementation-defined. + * + * <p>SQL`16 part 2 section 6.1 syntax rule 25 + */ + public static final int DEFAULT_DECIMAL_PRECISION = 19; + /** + * Default DECIMAL scale is implementation-defined. + * + * <p>SQL`16 part 2 section 6.1 syntax rule 25 + */ + public static final int DEFAULT_DECIMAL_SCALE = 3; + private static final Map<ColumnType, Set<ColumnType>> ALTER_COLUMN_TYPE_TRANSITIONS = new EnumMap<>(ColumnType.class); static { @@ -125,9 +150,9 @@ public class CatalogUtils { * @return Column descriptor. */ public static CatalogTableColumnDescriptor fromParams(ColumnParams params) { - int precision = params.precision() != null ? params.precision() : 0; - int scale = params.scale() != null ? params.scale() : 0; - int length = params.length() != null ? params.length() : 0; + int precision = params.precision() != null ? params.precision() : defaultPrecision(params.type()); + int scale = params.scale() != null ? params.scale() : defaultScale(params.type()); + int length = params.length() != null ? params.length() : defaultLength(params.type()); DefaultValue defaultValue = params.defaultValueDefinition(); return new CatalogTableColumnDescriptor(params.name(), params.type(), params.nullable(), @@ -146,4 +171,42 @@ public class CatalogUtils { return supportedTransitions != null && supportedTransitions.contains(target); } + + private static int defaultPrecision(ColumnType columnType) { + //TODO IGNITE-19938: Add REAL,FLOAT and DOUBLE precision. See SQL`16 part 2 section 6.1 syntax rule 29-31 + switch (columnType) { + case NUMBER: + case DECIMAL: + return DEFAULT_DECIMAL_PRECISION; + case TIME: + return DEFAULT_TIME_PRECISION; + case TIMESTAMP: + case DATETIME: + return DEFAULT_TIMESTAMP_PRECISION; + default: + return 0; + } + } + + private static int defaultScale(ColumnType columnType) { + //TODO IGNITE-19938: Add REAL,FLOAT and DOUBLE precision. See SQL`16 part 2 section 6.1 syntax rule 29-31 + if (columnType == ColumnType.DECIMAL) { + return DEFAULT_DECIMAL_SCALE; + } + + return 0; + } + + private static int defaultLength(ColumnType columnType) { + //TODO IGNITE-19938: Return length for other types. See SQL`16 part 2 section 6.1 syntax rule 39 + switch (columnType) { + case BITMASK: + case STRING: + case BYTE_ARRAY: + return Integer.MAX_VALUE; + default: + return 0; + } + } + } diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/ColumnParams.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/ColumnParams.java index f95e0544d7..9a57887652 100644 --- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/ColumnParams.java +++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/ColumnParams.java @@ -158,7 +158,7 @@ public class ColumnParams { * * @return {@code this}. */ - public Builder precision(int precision) { + public Builder precision(Integer precision) { params.precision = precision; return this; @@ -169,7 +169,7 @@ public class ColumnParams { * * @return {@code this}. */ - public Builder scale(int scale) { + public Builder scale(Integer scale) { params.scale = scale; return this; @@ -180,7 +180,7 @@ public class ColumnParams { * * @return {@code this}. */ - public Builder length(int length) { + public Builder length(Integer length) { params.length = length; return this; diff --git a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerSelfTest.java b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerSelfTest.java index a1ef062a31..61b4407ff7 100644 --- a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerSelfTest.java +++ b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerSelfTest.java @@ -412,7 +412,7 @@ public class CatalogManagerSelfTest extends BaseIgniteAbstractTest { assertEquals(DefaultValue.Type.CONSTANT, column.defaultValue().type()); assertEquals("Ignite!", ((DefaultValue.ConstantValue) column.defaultValue()).value()); - assertEquals(0, column.length()); + assertEquals(Integer.MAX_VALUE, column.length()); assertEquals(0, column.precision()); assertEquals(0, column.scale()); } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/configuration/storage/ItRebalanceDistributedTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/configuration/storage/ItRebalanceDistributedTest.java index a57cbb8250..7e102e3c62 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/configuration/storage/ItRebalanceDistributedTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/configuration/storage/ItRebalanceDistributedTest.java @@ -125,7 +125,7 @@ import org.apache.ignite.internal.schema.configuration.defaultvalue.ConstantValu import org.apache.ignite.internal.schema.configuration.defaultvalue.FunctionCallDefaultConfigurationSchema; import org.apache.ignite.internal.schema.configuration.defaultvalue.NullValueDefaultConfigurationSchema; import org.apache.ignite.internal.schema.configuration.index.HashIndexConfigurationSchema; -import org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter; +import org.apache.ignite.internal.schema.testutils.SchemaToCatalogParamsConverter; import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders; import org.apache.ignite.internal.schema.testutils.definition.ColumnType; import org.apache.ignite.internal.schema.testutils.definition.TableDefinition; @@ -271,9 +271,7 @@ public class ItRebalanceDistributedTest extends BaseIgniteAbstractTest { ).withPrimaryKey("key").build(); await(nodes.get(0).tableManager.createTableAsync( - "TBL1", - ZONE_1_NAME, - tblChanger -> SchemaConfigurationConverter.convert(schTbl1, tblChanger) + SchemaToCatalogParamsConverter.toCreateTable(ZONE_1_NAME, schTbl1) )); assertEquals(1, getPartitionClusterNodes(0, 0).size()); @@ -297,9 +295,7 @@ public class ItRebalanceDistributedTest extends BaseIgniteAbstractTest { ).withPrimaryKey("key").build(); await(nodes.get(0).tableManager.createTableAsync( - "TBL1", - ZONE_1_NAME, - tblChanger -> SchemaConfigurationConverter.convert(schTbl1, tblChanger) + SchemaToCatalogParamsConverter.toCreateTable(ZONE_1_NAME, schTbl1) )); assertEquals(1, getPartitionClusterNodes(0, 0).size()); @@ -324,9 +320,8 @@ public class ItRebalanceDistributedTest extends BaseIgniteAbstractTest { ).withPrimaryKey("key").build(); await(nodes.get(0).tableManager.createTableAsync( - "TBL1", - ZONE_1_NAME, - tblChanger -> SchemaConfigurationConverter.convert(schTbl1, tblChanger))); + SchemaToCatalogParamsConverter.toCreateTable(ZONE_1_NAME, schTbl1) + )); assertEquals(1, getPartitionClusterNodes(0, 0).size()); @@ -354,9 +349,8 @@ public class ItRebalanceDistributedTest extends BaseIgniteAbstractTest { // Tests that the distribution zone created on node0 is available on node1. TableImpl table = (TableImpl) await(nodes.get(1).tableManager.createTableAsync( - "TBL1", - zoneName, - tblChanger -> SchemaConfigurationConverter.convert(schTbl1, tblChanger))); + SchemaToCatalogParamsConverter.toCreateTable(zoneName, schTbl1) + )); Set<String> partitionNodesConsistentIds = getPartitionClusterNodes(0, 0).stream() .map(Assignment::consistentId) @@ -417,9 +411,8 @@ public class ItRebalanceDistributedTest extends BaseIgniteAbstractTest { ).withPrimaryKey("key").build(); await(nodes.get(0).tableManager.createTableAsync( - "TBL1", - ZONE_1_NAME, - tblChanger -> SchemaConfigurationConverter.convert(schTbl1, tblChanger))); + SchemaToCatalogParamsConverter.toCreateTable(ZONE_1_NAME, schTbl1) + )); assertEquals(1, getPartitionClusterNodes(0, 0).size()); @@ -822,6 +815,7 @@ public class ItRebalanceDistributedTest extends BaseIgniteAbstractTest { dataStorageMgr, storagePath, metaStorageManager, + catalogManager, schemaManager, view -> new LocalLogStorageFactory(), new HybridClockImpl(), @@ -1009,11 +1003,7 @@ public class ItRebalanceDistributedTest extends BaseIgniteAbstractTest { assertThat( nodes.get(0).tableManager.createTableAsync( - tableName, - zoneName, - tableChange -> { - SchemaConfigurationConverter.convert(createTableDefinition(tableName), tableChange); - } + SchemaToCatalogParamsConverter.toCreateTable(zoneName, createTableDefinition(tableName)) ), willCompleteSuccessfully() ); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/inmemory/ItRaftStorageVolatilityTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/inmemory/ItRaftStorageVolatilityTest.java index 9c7f7d4115..e19cb341e0 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/inmemory/ItRaftStorageVolatilityTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/inmemory/ItRaftStorageVolatilityTest.java @@ -21,7 +21,6 @@ import static ca.seinesoftware.hamcrest.path.PathMatcher.exists; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.toList; import static org.apache.ignite.internal.distributionzones.DistributionZoneManager.DEFAULT_PARTITION_COUNT; -import static org.apache.ignite.internal.distributionzones.DistributionZoneManager.DEFAULT_ZONE_NAME; import static org.apache.ignite.internal.distributionzones.DistributionZonesTestUtil.createZone; import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; import static org.hamcrest.MatcherAssert.assertThat; @@ -42,7 +41,7 @@ import org.apache.ignite.internal.ClusterPerTestIntegrationTest; import org.apache.ignite.internal.app.IgniteImpl; import org.apache.ignite.internal.raft.configuration.EntryCountBudgetChange; import org.apache.ignite.internal.raft.configuration.RaftConfiguration; -import org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter; +import org.apache.ignite.internal.schema.testutils.SchemaToCatalogParamsConverter; import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders; import org.apache.ignite.internal.schema.testutils.definition.ColumnType; import org.apache.ignite.internal.schema.testutils.definition.TableDefinition; @@ -240,7 +239,7 @@ class ItRaftStorageVolatilityTest extends ClusterPerTestIntegrationTest { } private void createTableWithMaxOneInMemoryEntryAllowed(String tableName) { - int zoneId = await(createZone( + await(createZone( node(0).distributionZoneManager(), "zone1", 1, DEFAULT_PARTITION_COUNT, dataStorageChange -> dataStorageChange.convert(VolatilePageMemoryDataStorageChange.class))); @@ -249,9 +248,8 @@ class ItRaftStorageVolatilityTest extends ClusterPerTestIntegrationTest { SchemaBuilders.column("NAME", ColumnType.string()).asNullable(true).build() ).withPrimaryKey("ID").build(); - await(((TableManager) node(0).tables()).createTableAsync(tableName, DEFAULT_ZONE_NAME, tableChange -> { - SchemaConfigurationConverter.convert(tableDef, tableChange) - .changeZoneId(zoneId); - })); + await(((TableManager) node(0).tables()).createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable("zone1", tableDef) + )); } } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java index cfc9bc7c9d..0f3069a620 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java @@ -354,7 +354,7 @@ class ItTableRaftSnapshotsTest extends IgniteIntegrationTest { } private void createTestTableWith3Replicas(String storageEngine) throws InterruptedException { - String zoneSql = "create zone test_zone" + String zoneSql = "create zone TEST_ZONE" + (DEFAULT_STORAGE_ENGINE.equals(storageEngine) ? "" : " engine " + storageEngine) + " with partitions=1, replicas=3;"; String sql = "create table test (key int primary key, value varchar(20))" diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java index 4a562affdb..1b782195ce 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java @@ -153,10 +153,10 @@ public class ItIgniteNodeRestartTest extends BaseIgniteRestartTest { private static final IntFunction<String> VALUE_PRODUCER = i -> "val " + i; /** Test table name. */ - private static final String TABLE_NAME = "Table1"; + private static final String TABLE_NAME = "Table1".toUpperCase(); /** Test table name. */ - private static final String TABLE_NAME_2 = "Table2"; + private static final String TABLE_NAME_2 = "Table2".toUpperCase(); @InjectConfiguration("mock: " + RAFT_CFG) private static RaftConfiguration raftConfiguration; @@ -375,6 +375,7 @@ public class ItIgniteNodeRestartTest extends BaseIgniteRestartTest { dataStorageManager, storagePath, metaStorageMgr, + catalogManager, schemaManager, view -> new LocalLogStorageFactory(), hybridClock, diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItSchemaChangeKvViewTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItSchemaChangeKvViewTest.java index deb86eaadf..197d44d38c 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItSchemaChangeKvViewTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItSchemaChangeKvViewTest.java @@ -28,11 +28,13 @@ import org.apache.ignite.Ignite; import org.apache.ignite.internal.schema.SchemaMismatchException; import org.apache.ignite.table.KeyValueView; import org.apache.ignite.table.Tuple; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** * Ignition interface tests. */ +@Disabled("IGNITE-19499") class ItSchemaChangeKvViewTest extends AbstractSchemaChangeTest { /** * Check add a new column to table schema. diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItSchemaChangeTableViewTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItSchemaChangeTableViewTest.java index 9906221940..b759356c78 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItSchemaChangeTableViewTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItSchemaChangeTableViewTest.java @@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test; /** * Ignition interface tests. */ +@Disabled("IGNITE-19499") class ItSchemaChangeTableViewTest extends AbstractSchemaChangeTest { /** * Check add a new column to table schema. diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTableApiContractTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTableApiContractTest.java index 91da7e94e7..a60da2e800 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTableApiContractTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTableApiContractTest.java @@ -19,7 +19,6 @@ package org.apache.ignite.internal.runner.app; import static java.util.stream.Collectors.toList; import static org.apache.ignite.internal.distributionzones.DistributionZoneManager.DEFAULT_ZONE_NAME; -import static org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter.convert; import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; @@ -34,8 +33,14 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.stream.IntStream; import org.apache.ignite.Ignite; +import org.apache.ignite.internal.catalog.commands.AlterTableAddColumnParams; +import org.apache.ignite.internal.catalog.commands.ColumnParams; +import org.apache.ignite.internal.catalog.commands.DefaultValue; +import org.apache.ignite.internal.catalog.commands.DropTableParams; +import org.apache.ignite.internal.schema.testutils.SchemaToCatalogParamsConverter; import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders; import org.apache.ignite.internal.schema.testutils.definition.ColumnType; +import org.apache.ignite.internal.schema.testutils.definition.TableDefinition; import org.apache.ignite.internal.sql.engine.ClusterPerClassIntegrationTest; import org.apache.ignite.internal.table.distributed.TableManager; import org.apache.ignite.lang.TableAlreadyExistsException; @@ -142,13 +147,19 @@ public class ItTableApiContractTest extends ClusterPerClassIntegrationTest { */ @Test public void testDropTable() throws Exception { - CompletableFuture<Void> dropTblFut1 = tableManager().dropTableAsync(TABLE_NAME); + CompletableFuture<Void> dropTblFut1 = tableManager().dropTableAsync(DropTableParams.builder() + .schemaName(SCHEMA) + .tableName(TABLE_NAME) + .build()); dropTblFut1.get(); assertNull(ignite.tables().table(TABLE_NAME)); - CompletableFuture<Void> dropTblFut2 = tableManager().dropTableAsync(TABLE_NAME); + CompletableFuture<Void> dropTblFut2 = tableManager().dropTableAsync(DropTableParams.builder() + .schemaName(SCHEMA) + .tableName(TABLE_NAME) + .build()); assertThrows(TableNotFoundException.class, () -> futureResult(dropTblFut2)); } @@ -160,23 +171,29 @@ public class ItTableApiContractTest extends ClusterPerClassIntegrationTest { */ @Test public void testAlterTable() throws Exception { - await(tableManager().alterTableAsync(TABLE_NAME, chng -> { - chng.changeColumns(cols -> - cols.create("NAME_1", colChg -> convert(SchemaBuilders.column("NAME_1", ColumnType.string()).asNullable(true) - .withDefaultValue("default").build(), colChg))); - return true; - })); + await(tableManager().alterTableAddColumnAsync(AlterTableAddColumnParams.builder() + .schemaName(SCHEMA) + .tableName(TABLE_NAME) + .columns(List.of( + ColumnParams.builder().name("NAME_1").type(org.apache.ignite.sql.ColumnType.STRING).nullable(true) + .defaultValue(DefaultValue.constant("default")).build() + )) + .build() + )); assertNotNull(ignite.tables().table(TABLE_NAME)); - assertNull(ignite.tables().table(TABLE_NAME + "_not_exist")); - - assertThrows(TableNotFoundException.class, () -> await(tableManager().alterTableAsync(TABLE_NAME + "_not_exist", chng -> { - chng.changeColumns(cols -> - cols.create("NAME_1", colChg -> convert(SchemaBuilders.column("NAME_1", ColumnType.string()).asNullable(true) - .withDefaultValue("default").build(), colChg))); - return true; - }))); + assertNull(ignite.tables().table("UNKNOWN")); + + assertThrows(TableNotFoundException.class, () -> await(tableManager().alterTableAddColumnAsync(AlterTableAddColumnParams.builder() + .schemaName(SCHEMA) + .tableName("UNKNOWN") + .columns(List.of( + ColumnParams.builder().name("NAME_1").type(org.apache.ignite.sql.ColumnType.STRING).nullable(true) + .defaultValue(DefaultValue.constant("default")).build() + )) + .build() + ))); } /** @@ -186,68 +203,49 @@ public class ItTableApiContractTest extends ClusterPerClassIntegrationTest { */ @Test public void testAlterTableAsync() throws Exception { - CompletableFuture<Void> altTblFut1 = tableManager().alterTableAsync(TABLE_NAME, - chng -> { - chng.changeColumns(cols -> - cols.create("NAME_1", colChg -> convert(SchemaBuilders.column("NAME_1", - ColumnType.string()).asNullable(true).withDefaultValue("default").build(), colChg))); - return true; - }); - - CompletableFuture<Void> altTblFut2 = tableManager().alterTableAsync(TABLE_NAME + "_not_exist", - chng -> { - chng.changeColumns(cols -> - cols.create("NAME_1", colChg -> convert(SchemaBuilders.column("NAME_1", - ColumnType.string()).asNullable(true).withDefaultValue("default").build(), colChg))); - return true; - }); + CompletableFuture<Void> altTblFut1 = tableManager().alterTableAddColumnAsync(AlterTableAddColumnParams.builder() + .schemaName(SCHEMA) + .tableName(TABLE_NAME) + .columns(List.of( + ColumnParams.builder().name("NAME_1").type(org.apache.ignite.sql.ColumnType.STRING).nullable(true) + .defaultValue(DefaultValue.constant("default")).build() + )) + .build()); + + CompletableFuture<Void> altTblFut2 = tableManager().alterTableAddColumnAsync(AlterTableAddColumnParams.builder() + .schemaName(SCHEMA) + .tableName("UNKNOWN") + .columns(List.of( + ColumnParams.builder().name("NAME_1").type(org.apache.ignite.sql.ColumnType.STRING).nullable(true) + .defaultValue(DefaultValue.constant("default")).build() + )) + .build()); assertNotNull(ignite.tables().table(TABLE_NAME)); - assertNull(ignite.tables().table(TABLE_NAME + "_not_exist")); + assertNull(ignite.tables().table("UNKNOWN")); altTblFut1.get(); assertThrows(TableNotFoundException.class, () -> futureResult(altTblFut2)); } - /** - * Checks a contract for table creation. - * - * @throws Exception If failed. - */ - @Test - public void testCreateTable() throws Exception { - Table table = ignite.tables().table(TABLE_NAME); - - assertNotNull(table); - - assertThrows(TableAlreadyExistsException.class, - () -> await(tableManager().createTableAsync(TABLE_NAME, DEFAULT_ZONE_NAME, - tableChange -> convert(SchemaBuilders.tableBuilder(SCHEMA, TABLE_NAME) - .columns( - SchemaBuilders.column("new_key", ColumnType.INT64).build(), - SchemaBuilders.column("new_val", ColumnType.string()).build()) - .withPrimaryKey("new_key") - .build(), tableChange)))); - } - /** * Checks a contract for asynchronous table creation. - * - * @throws Exception If failed. */ @Test - public void testCreateTableAsync() throws Exception { + public void testCreateTableAsync() { assertNotNull(ignite.tables().table(TABLE_NAME)); + TableDefinition tableDefinition = SchemaBuilders.tableBuilder(SCHEMA, TABLE_NAME) + .columns( + SchemaBuilders.column("new_key", ColumnType.INT64).build(), + SchemaBuilders.column("new_val", ColumnType.string()).build()) + .withPrimaryKey("new_key") + .build(); + CompletableFuture<Table> tableFut2 = tableManager() - .createTableAsync(TABLE_NAME, DEFAULT_ZONE_NAME, tableChange -> convert(SchemaBuilders.tableBuilder(SCHEMA, TABLE_NAME) - .columns( - SchemaBuilders.column("new_key", ColumnType.INT64).build(), - SchemaBuilders.column("new_val", ColumnType.string()).build()) - .withPrimaryKey("new_key") - .build(), tableChange)); + .createTableAsync(SchemaToCatalogParamsConverter.toCreateTable(DEFAULT_ZONE_NAME, tableDefinition)); assertThrows(TableAlreadyExistsException.class, () -> futureResult(tableFut2)); } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java index cb96e88300..c4fc440077 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java @@ -20,7 +20,6 @@ package org.apache.ignite.internal.runner.app; import static java.util.concurrent.CompletableFuture.runAsync; import static java.util.concurrent.CompletableFuture.supplyAsync; import static org.apache.ignite.internal.distributionzones.DistributionZoneManager.DEFAULT_ZONE_NAME; -import static org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter.convert; import static org.apache.ignite.internal.test.WatchListenerInhibitor.metastorageEventsInhibitor; import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName; @@ -44,6 +43,9 @@ import java.util.stream.IntStream; import org.apache.ignite.Ignite; import org.apache.ignite.IgnitionManager; import org.apache.ignite.InitParameters; +import org.apache.ignite.internal.catalog.commands.AlterTableAddColumnParams; +import org.apache.ignite.internal.catalog.commands.DropTableParams; +import org.apache.ignite.internal.schema.testutils.SchemaToCatalogParamsConverter; import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders; import org.apache.ignite.internal.schema.testutils.definition.ColumnDefinition; import org.apache.ignite.internal.schema.testutils.definition.ColumnType; @@ -442,7 +444,10 @@ public class ItTablesApiTest extends IgniteAbstractTest { ignite1Inhibitor.startInhibit(); - await(((TableManager) clusterNodes.get(0).tables()).dropTableAsync(TABLE_NAME)); + await(((TableManager) clusterNodes.get(0).tables()).dropTableAsync(DropTableParams.builder() + .schemaName(SCHEMA) + .tableName(TABLE_NAME) + .build())); // Because the event inhibitor was started, last metastorage updates do not reach to one node. // Therefore the table still exists locally, but API prevents getting it. @@ -466,11 +471,6 @@ public class ItTablesApiTest extends IgniteAbstractTest { * @param tableName Table name. */ protected Table createTable(Ignite node, String tableName) { - List<ColumnDefinition> cols = new ArrayList<>(); - cols.add(SchemaBuilders.column("key", ColumnType.INT64).build()); - cols.add(SchemaBuilders.column("valInt", ColumnType.INT32).asNullable(true).build()); - cols.add(SchemaBuilders.column("valStr", ColumnType.string()).withDefaultValue("default").build()); - var tmpl = "CREATE TABLE %s (key BIGINT PRIMARY KEY, valInt INT, valStr VARCHAR)"; var sql = String.format(tmpl, tableName); @@ -489,17 +489,19 @@ public class ItTablesApiTest extends IgniteAbstractTest { */ protected Table createTableIfNotExists(Ignite node, String tableName) { try { - return await(((TableManager) node.tables()).createTableAsync( - tableName, - DEFAULT_ZONE_NAME, - tblCh -> convert(SchemaBuilders.tableBuilder(SCHEMA, tableName).columns(Arrays.asList( + TableManager tableManager = (TableManager) node.tables(); + + await(tableManager.createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(DEFAULT_ZONE_NAME, + SchemaBuilders.tableBuilder(SCHEMA, tableName).columns(Arrays.asList( SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("valInt", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("valStr", ColumnType.string()) .withDefaultValue("default").build() - )).withPrimaryKey("key").build(), - tblCh) + )).withPrimaryKey("key").build()) )); + + return tableManager.table(tableName); } catch (TableAlreadyExistsException ex) { return node.tables().table(tableName); } @@ -512,7 +514,10 @@ public class ItTablesApiTest extends IgniteAbstractTest { * @param tableName Table name. */ protected void dropTable(Ignite node, String tableName) { - await(((TableManager) node.tables()).dropTableAsync(tableName)); + await(((TableManager) node.tables()).dropTableAsync(DropTableParams.builder() + .schemaName(SCHEMA) + .tableName(TABLE_NAME) + .build())); } /** @@ -523,7 +528,10 @@ public class ItTablesApiTest extends IgniteAbstractTest { */ protected void dropTableIfExists(Ignite node, String tableName) { try { - await(((TableManager) node.tables()).dropTableAsync(tableName)); + await(((TableManager) node.tables()).dropTableAsync(DropTableParams.builder() + .schemaName(SCHEMA) + .tableName(tableName) + .build())); } catch (TableNotFoundException ex) { log.info("Dropping the table ignored.", ex); } @@ -550,18 +558,12 @@ public class ItTablesApiTest extends IgniteAbstractTest { * @param colDefinition Column defenition. */ private void addColumnInternal(Ignite node, String tableName, ColumnDefinition colDefinition) { - await(((TableManager) node.tables()).alterTableAsync( - tableName, - chng -> { - chng.changeColumns(cols -> { - try { - cols.create(colDefinition.name(), colChg -> convert(colDefinition, colChg)); - } catch (IllegalArgumentException e) { - throw new ColumnAlreadyExistsException(colDefinition.name()); - } - }); - return true; - })); + await(((TableManager) node.tables()).alterTableAddColumnAsync( + AlterTableAddColumnParams.builder() + .schemaName(SCHEMA) + .tableName(tableName) + .columns(List.of(SchemaToCatalogParamsConverter.convert(colDefinition))) + .build())); } /** diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java index 67579912c5..c279aa9f62 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/PlatformTestNodeRunner.java @@ -48,7 +48,7 @@ import org.apache.ignite.internal.schema.SchemaDescriptor; import org.apache.ignite.internal.schema.marshaller.TupleMarshallerException; import org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl; import org.apache.ignite.internal.schema.row.Row; -import org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter; +import org.apache.ignite.internal.schema.testutils.SchemaToCatalogParamsConverter; import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders; import org.apache.ignite.internal.schema.testutils.definition.ColumnType; import org.apache.ignite.internal.schema.testutils.definition.ColumnType.TemporalColumnType; @@ -267,8 +267,8 @@ public class PlatformTestNodeRunner { SchemaBuilders.column("val", ColumnType.string()).asNullable(true).build() ).withPrimaryKey(keyCol).build(); - await(((TableManager) node.tables()).createTableAsync(schTbl.name(), ZONE_NAME, tblCh -> - SchemaConfigurationConverter.convert(schTbl, tblCh) + await(((TableManager) node.tables()).createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(ZONE_NAME, schTbl) )); int maxTimePrecision = TemporalColumnType.MAX_TIME_PRECISION; @@ -295,8 +295,8 @@ public class PlatformTestNodeRunner { SchemaBuilders.column("decimal", ColumnType.decimal()).asNullable(true).build() ).withPrimaryKey(keyCol).build(); - await(((TableManager) node.tables()).createTableAsync(schTblAll.name(), ZONE_NAME, tblCh -> - SchemaConfigurationConverter.convert(schTblAll, tblCh) + await(((TableManager) node.tables()).createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(ZONE_NAME, schTblAll) )); // TODO IGNITE-18431 remove extra table, use TABLE_NAME_ALL_COLUMNS for SQL tests. @@ -321,8 +321,8 @@ public class PlatformTestNodeRunner { SchemaBuilders.column("decimal", ColumnType.decimal()).asNullable(true).build() ).withPrimaryKey(keyCol).build(); - await(((TableManager) node.tables()).createTableAsync(schTblAllSql.name(), ZONE_NAME, tblCh -> - SchemaConfigurationConverter.convert(schTblAllSql, tblCh) + await(((TableManager) node.tables()).createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(ZONE_NAME, schTblAllSql) )); createTwoColumnTable(node, ColumnType.INT8); @@ -351,8 +351,8 @@ public class PlatformTestNodeRunner { SchemaBuilders.column("val", type).asNullable(true).build() ).withPrimaryKey(keyCol).build(); - await(((TableManager) node.tables()).createTableAsync(schTbl.name(), ZONE_NAME, tblCh -> - SchemaConfigurationConverter.convert(schTbl, tblCh) + await(((TableManager) node.tables()).createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(ZONE_NAME, schTbl) )); } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItCommonApiTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItCommonApiTest.java index 2211137be9..0c1d3b55e9 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItCommonApiTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItCommonApiTest.java @@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit; import org.apache.calcite.schema.SchemaPlus; import org.apache.ignite.Ignite; import org.apache.ignite.internal.app.IgniteImpl; -import org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter; +import org.apache.ignite.internal.schema.testutils.SchemaToCatalogParamsConverter; import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders; import org.apache.ignite.internal.schema.testutils.definition.ColumnType; import org.apache.ignite.internal.schema.testutils.definition.ColumnType.TemporalColumnType; @@ -144,8 +144,8 @@ public class ItCommonApiTest extends ClusterPerClassIntegrationTest { SchemaBuilders.column("datetime", ColumnType.datetime(maxTimePrecision)).asNullable(true).build() ).withPrimaryKey(keyCol).build(); - await(((TableManager) node.tables()).createTableAsync(schTblAllSql.name(), DEFAULT_ZONE_NAME, tblCh -> - SchemaConfigurationConverter.convert(schTblAllSql, tblCh) + await(((TableManager) node.tables()).createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(DEFAULT_ZONE_NAME, schTblAllSql) )); Table tbl = node.tables().table(kvTblName); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlAsynchronousApiTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlAsynchronousApiTest.java index 473d6399f7..105463070c 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlAsynchronousApiTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlAsynchronousApiTest.java @@ -22,7 +22,6 @@ import static org.apache.ignite.internal.sql.engine.util.QueryChecker.containsTa import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause; import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; import static org.apache.ignite.lang.ErrorGroups.Sql.CONSTRAINT_VIOLATION_ERR; -import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_VALIDATION_ERR; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -182,26 +181,21 @@ public class ItSqlAsynchronousApiTest extends ClusterPerClassIntegrationTest { checkError( SqlException.class, - "Can`t delete column(s). Column VAL1 is used by indexes [TEST_IDX3].", + "Can't drop indexed column: [columnName=VAL1, indexName=TEST_IDX3]", ses, "ALTER TABLE TEST DROP COLUMN val1" ); - SqlException ex = IgniteTestUtils.cause(assertThrows(Throwable.class, - () -> await(ses.executeAsync(null, "ALTER TABLE TEST DROP COLUMN (val0, val1)"))), SqlException.class); - assertNotNull(ex); - assertEquals(STMT_VALIDATION_ERR, ex.code()); - - String msg = ex.getMessage(); - String explainMsg = "Unexpected error message: " + msg; - - assertTrue(msg.contains("Column VAL0 is used by indexes ["), explainMsg); - assertTrue(msg.contains("TEST_IDX1") && msg.contains("TEST_IDX2") && msg.contains("TEST_IDX3"), explainMsg); - assertTrue(msg.contains("Column VAL1 is used by indexes [TEST_IDX3]"), explainMsg); + checkError( + SqlException.class, + "Can't drop indexed column: [columnName=VAL0, indexName=TEST_IDX1]", + ses, + "ALTER TABLE TEST DROP COLUMN (val0, val1)" + ); checkError( SqlException.class, - "Can`t delete column, belongs to primary key: [name=ID]", + "Can't drop primary key column: [name=ID]", ses, "ALTER TABLE TEST DROP COLUMN id" ); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlSynchronousApiTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlSynchronousApiTest.java index 376f71f63f..f2c713c34c 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlSynchronousApiTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/api/ItSqlSynchronousApiTest.java @@ -18,11 +18,8 @@ package org.apache.ignite.internal.sql.api; import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause; -import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; -import static org.apache.ignite.lang.ErrorGroups.Sql.STMT_VALIDATION_ERR; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -165,26 +162,21 @@ public class ItSqlSynchronousApiTest extends ClusterPerClassIntegrationTest { checkError( SqlException.class, - "Can`t delete column(s). Column VAL1 is used by indexes [TEST_IDX3].", + "Can't drop indexed column: [columnName=VAL1, indexName=TEST_IDX3]", ses, "ALTER TABLE TEST DROP COLUMN val1" ); - SqlException ex = IgniteTestUtils.cause(assertThrows(Throwable.class, - () -> await(ses.executeAsync(null, "ALTER TABLE TEST DROP COLUMN (val0, val1)"))), SqlException.class); - assertNotNull(ex); - assertEquals(STMT_VALIDATION_ERR, ex.code()); - - String msg = ex.getMessage(); - String explainMsg = "Unexpected error message: " + msg; - - assertTrue(msg.contains("Column VAL0 is used by indexes ["), explainMsg); - assertTrue(msg.contains("TEST_IDX1") && msg.contains("TEST_IDX2") && msg.contains("TEST_IDX3"), explainMsg); - assertTrue(msg.contains("Column VAL1 is used by indexes [TEST_IDX3]"), explainMsg); + checkError( + SqlException.class, + "Can't drop indexed column: [columnName=VAL0, indexName=TEST_IDX1]", + ses, + "ALTER TABLE TEST DROP COLUMN (val0, val1)" + ); checkError( SqlException.class, - "Can`t delete column, belongs to primary key: [name=ID]", + "Can't drop primary key column: [name=ID]", ses, "ALTER TABLE TEST DROP COLUMN id" ); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java index 6f81d7e757..d292d3246f 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItCreateTableDdlTest.java @@ -25,13 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; -import org.apache.ignite.Ignite; -import org.apache.ignite.internal.configuration.ConfigurationManager; import org.apache.ignite.internal.schema.Column; -import org.apache.ignite.internal.schema.configuration.ExtendedTableView; -import org.apache.ignite.internal.schema.configuration.TablesConfiguration; import org.apache.ignite.internal.table.TableImpl; -import org.apache.ignite.internal.testframework.IgniteTestUtils; import org.apache.ignite.lang.IgniteException; import org.apache.ignite.sql.SqlException; import org.junit.jupiter.api.AfterEach; @@ -150,7 +145,7 @@ public class ItCreateTableDdlTest extends ClusterPerClassIntegrationTest { IgniteException.class, () -> sql("CREATE TABLE T0(ID0 INT, ID1 INT, VAL INT, PRIMARY KEY (ID1, ID0)) COLOCATE (ID1, ID0, ID1)") ).getMessage(), - containsString("Colocation columns contains duplicates: [duplicates=[ID1]]]") + containsString("Colocation columns contains duplicates: ID1, ID0, ID1") ); } @@ -202,29 +197,6 @@ public class ItCreateTableDdlTest extends ClusterPerClassIntegrationTest { assertEquals(3, res.get(0).get(0)); } - /** - * Checks that schema version is updated even if column names are intersected. - */ - // Need to be removed after https://issues.apache.org/jira/browse/IGNITE-19082 - @Test - public void checkSchemaUpdatedWithEqAlterColumn() { - sql("CREATE TABLE TEST(ID INT PRIMARY KEY, VAL0 INT)"); - - Ignite node = CLUSTER_NODES.get(0); - - ConfigurationManager cfgMgr = IgniteTestUtils.getFieldValue(node, "clusterCfgMgr"); - - TablesConfiguration tablesConfiguration = cfgMgr.configurationRegistry().getConfiguration(TablesConfiguration.KEY); - - int schIdBefore = ((ExtendedTableView) tablesConfiguration.tables().get("TEST").value()).schemaId(); - - sql("ALTER TABLE TEST ADD COLUMN (VAL1 INT)"); - - int schIdAfter = ((ExtendedTableView) tablesConfiguration.tables().get("TEST").value()).schemaId(); - - assertEquals(schIdBefore + 1, schIdAfter); - } - /** * Check explicit colocation columns configuration. */ diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItRoReadsTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItRoReadsTest.java index ff2a3b83f1..55bf5008eb 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItRoReadsTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItRoReadsTest.java @@ -20,7 +20,6 @@ package org.apache.ignite.internal.table; import static org.apache.ignite.internal.distributionzones.DistributionZoneManager.DEFAULT_REPLICA_COUNT; import static org.apache.ignite.internal.distributionzones.DistributionZonesTestUtil.createZone; import static org.apache.ignite.internal.runner.app.ItTablesApiTest.SCHEMA; -import static org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter.convert; import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName; import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; @@ -43,6 +42,7 @@ import org.apache.ignite.Ignite; import org.apache.ignite.IgnitionManager; import org.apache.ignite.InitParameters; import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.catalog.commands.DropTableParams; import org.apache.ignite.internal.logger.IgniteLogger; import org.apache.ignite.internal.logger.Loggers; import org.apache.ignite.internal.schema.BinaryRow; @@ -52,6 +52,7 @@ import org.apache.ignite.internal.schema.NativeTypes; import org.apache.ignite.internal.schema.SchemaDescriptor; import org.apache.ignite.internal.schema.row.Row; import org.apache.ignite.internal.schema.row.RowAssembler; +import org.apache.ignite.internal.schema.testutils.SchemaToCatalogParamsConverter; import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders; import org.apache.ignite.internal.schema.testutils.definition.ColumnDefinition; import org.apache.ignite.internal.schema.testutils.definition.ColumnType; @@ -82,7 +83,7 @@ import org.junit.jupiter.api.extension.ExtendWith; public class ItRoReadsTest extends BaseIgniteAbstractTest { private static final IgniteLogger LOG = Loggers.forClass(ItRoReadsTest.class); - private static final String TABLE_NAME = "some-table"; + private static final String TABLE_NAME = "some-table".toUpperCase(); private static final SchemaDescriptor SCHEMA_1 = new SchemaDescriptor( 1, @@ -522,18 +523,23 @@ public class ItRoReadsTest extends BaseIgniteAbstractTest { cols.add(SchemaBuilders.column("valStr", ColumnType.string()).withDefaultValue("default").build()); String zoneName = "zone_" + tableName; - int zoneId = await(createZone(((IgniteImpl) node).distributionZoneManager(), zoneName, 1, DEFAULT_REPLICA_COUNT)); + await(createZone(((IgniteImpl) node).distributionZoneManager(), zoneName, 1, DEFAULT_REPLICA_COUNT)); - return await(((TableManager) node.tables()).createTableAsync( - tableName, - zoneName, - tblCh -> convert(SchemaBuilders.tableBuilder(SCHEMA, tableName).columns( - cols).withPrimaryKey("key").build(), tblCh) + TableManager tableManager = (TableManager) node.tables(); + + await(tableManager.createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(zoneName, SchemaBuilders.tableBuilder(SCHEMA, tableName).columns( + cols).withPrimaryKey("key").build()) )); + + return tableManager.table(tableName); } private static void stopTable(Ignite node, String tableName) { - await(((TableManager) node.tables()).dropTableAsync(tableName)); + await(((TableManager) node.tables()).dropTableAsync(DropTableParams.builder() + .schemaName(SCHEMA) + .tableName(tableName) + .build())); await(((IgniteImpl) node).distributionZoneManager().dropZone("zone_" + tableName)); } diff --git a/modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java b/modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java index 94c63b5d6e..d38a1597e8 100644 --- a/modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java +++ b/modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java @@ -539,6 +539,7 @@ public class IgniteImpl implements Ignite { dataStorageMgr, storagePath, metaStorageMgr, + catalogManager, schemaManager, volatileLogStorageFactoryCreator, clock, diff --git a/modules/schema/build.gradle b/modules/schema/build.gradle index 92e8100a45..088019e4e4 100644 --- a/modules/schema/build.gradle +++ b/modules/schema/build.gradle @@ -52,6 +52,7 @@ dependencies { testFixturesImplementation project(':ignite-api') testFixturesImplementation project(':ignite-bytecode') testFixturesImplementation project(':ignite-configuration-api') + testFixturesImplementation project(':ignite-catalog') testFixturesImplementation(testFixtures(project(':ignite-core'))) testFixturesImplementation libs.jetbrains.annotations testFixturesImplementation libs.junit5.api diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/CatalogDescriptorUtils.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/CatalogDescriptorUtils.java index 8acc7aa194..54dca3f1b1 100644 --- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/CatalogDescriptorUtils.java +++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/CatalogDescriptorUtils.java @@ -22,7 +22,11 @@ import static org.apache.ignite.internal.catalog.descriptors.CatalogColumnCollat import static org.apache.ignite.internal.catalog.descriptors.CatalogColumnCollation.DESC_NULLS_FIRST; import java.util.List; +import org.apache.ignite.internal.catalog.commands.CatalogUtils; +import org.apache.ignite.internal.catalog.commands.ColumnParams; import org.apache.ignite.internal.catalog.commands.DefaultValue; +import org.apache.ignite.internal.catalog.commands.DefaultValue.ConstantValue; +import org.apache.ignite.internal.catalog.commands.DefaultValue.FunctionCall; import org.apache.ignite.internal.catalog.descriptors.CatalogColumnCollation; import org.apache.ignite.internal.catalog.descriptors.CatalogHashIndexDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogIndexColumnDescriptor; @@ -30,6 +34,8 @@ import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogSortedIndexDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogTableColumnDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; +import org.apache.ignite.internal.schema.configuration.ColumnChange; +import org.apache.ignite.internal.schema.configuration.ColumnTypeChange; import org.apache.ignite.internal.schema.configuration.ColumnTypeView; import org.apache.ignite.internal.schema.configuration.ColumnView; import org.apache.ignite.internal.schema.configuration.ConfigurationToSchemaDescriptorConverter; @@ -38,8 +44,11 @@ import org.apache.ignite.internal.schema.configuration.TableView; import org.apache.ignite.internal.schema.configuration.ValueSerializationHelper; import org.apache.ignite.internal.schema.configuration.defaultvalue.ColumnDefaultConfigurationSchema; import org.apache.ignite.internal.schema.configuration.defaultvalue.ColumnDefaultView; +import org.apache.ignite.internal.schema.configuration.defaultvalue.ConstantValueDefaultChange; import org.apache.ignite.internal.schema.configuration.defaultvalue.ConstantValueDefaultView; +import org.apache.ignite.internal.schema.configuration.defaultvalue.FunctionCallDefaultChange; import org.apache.ignite.internal.schema.configuration.defaultvalue.FunctionCallDefaultView; +import org.apache.ignite.internal.schema.configuration.defaultvalue.NullValueDefaultChange; import org.apache.ignite.internal.schema.configuration.index.HashIndexView; import org.apache.ignite.internal.schema.configuration.index.IndexColumnView; import org.apache.ignite.internal.schema.configuration.index.SortedIndexView; @@ -197,4 +206,106 @@ public class CatalogDescriptorUtils { return new CatalogIndexColumnDescriptor(config.name(), collation); } + + /** + * Applies changes from params to the configuraiton changer. + * + * @param params Column change parameters. + * @param columnChange Configuration changer. + */ + public static void convertColumnDefinition(ColumnParams params, ColumnChange columnChange) { + NativeType nativeType = getNativeType(CatalogUtils.fromParams(params)); + + columnChange.changeType(columnTypeChange -> convert(nativeType, columnTypeChange)); + columnChange.changeNullable(params.nullable()); + columnChange.changeDefaultValueProvider(defaultChange -> { + switch (params.defaultValueDefinition().type()) { + case CONSTANT: + ConstantValue constantValue = params.defaultValueDefinition(); + + var val = constantValue.value(); + + if (val != null) { + defaultChange.convert(ConstantValueDefaultChange.class) + .changeDefaultValue(ValueSerializationHelper.toString(val, nativeType)); + } else { + defaultChange.convert(NullValueDefaultChange.class); + } + + break; + case FUNCTION_CALL: + FunctionCall functionCall = params.defaultValueDefinition(); + + defaultChange.convert(FunctionCallDefaultChange.class) + .changeFunctionName(functionCall.functionName()); + + break; + default: + throw new IllegalStateException("Unknown default value definition type [type=" + + params.defaultValueDefinition().type() + ']'); + } + }); + } + + private static void convert(NativeType colType, ColumnTypeChange colTypeChg) { + NativeTypeSpec spec = colType.spec(); + String typeName = spec.name().toUpperCase(); + + colTypeChg.changeType(typeName); + + switch (spec) { + case INT8: + case INT16: + case INT32: + case INT64: + case FLOAT: + case DOUBLE: + case DATE: + case UUID: + // do nothing + break; + + case BITMASK: + BitmaskNativeType bitmaskColType = (BitmaskNativeType) colType; + + colTypeChg.changeLength(bitmaskColType.bits()); + + break; + + case BYTES: + case STRING: + VarlenNativeType varLenColType = (VarlenNativeType) colType; + + colTypeChg.changeLength(varLenColType.length()); + + break; + + case DECIMAL: + DecimalNativeType numColType = (DecimalNativeType) colType; + + colTypeChg.changePrecision(numColType.precision()); + colTypeChg.changeScale(numColType.scale()); + + break; + + case NUMBER: + NumberNativeType numType = (NumberNativeType) colType; + + colTypeChg.changePrecision(numType.precision()); + + break; + + case TIME: + case DATETIME: + case TIMESTAMP: + TemporalNativeType temporalColType = (TemporalNativeType) colType; + + colTypeChg.changePrecision(temporalColType.precision()); + + break; + + default: + throw new IllegalArgumentException("Unknown type " + colType.spec().name()); + } + } } diff --git a/modules/schema/src/testFixtures/java/org/apache/ignite/internal/schema/testutils/SchemaToCatalogParamsConverter.java b/modules/schema/src/testFixtures/java/org/apache/ignite/internal/schema/testutils/SchemaToCatalogParamsConverter.java new file mode 100644 index 0000000000..a00eda8c7f --- /dev/null +++ b/modules/schema/src/testFixtures/java/org/apache/ignite/internal/schema/testutils/SchemaToCatalogParamsConverter.java @@ -0,0 +1,208 @@ +/* + * 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.schema.testutils; + +import java.util.EnumSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.ignite.internal.catalog.commands.ColumnParams; +import org.apache.ignite.internal.catalog.commands.ColumnParams.Builder; +import org.apache.ignite.internal.catalog.commands.CreateTableParams; +import org.apache.ignite.internal.catalog.commands.DefaultValue; +import org.apache.ignite.internal.schema.testutils.definition.ColumnDefinition; +import org.apache.ignite.internal.schema.testutils.definition.ColumnType; +import org.apache.ignite.internal.schema.testutils.definition.DefaultValueDefinition.ConstantValue; +import org.apache.ignite.internal.schema.testutils.definition.DefaultValueDefinition.FunctionCall; +import org.apache.ignite.internal.schema.testutils.definition.TableDefinition; + +/** + * Schema to Catalog params converter. + */ +public class SchemaToCatalogParamsConverter { + /** + * Types map. + */ + private static final EnumSet<ColumnType.ColumnTypeSpec> fixSizedTypes = EnumSet.of( + ColumnType.INT8.typeSpec(), + ColumnType.INT16.typeSpec(), + ColumnType.INT32.typeSpec(), + ColumnType.INT64.typeSpec(), + ColumnType.FLOAT.typeSpec(), + ColumnType.DOUBLE.typeSpec(), + ColumnType.UUID.typeSpec(), + ColumnType.DATE.typeSpec() + ); + + /** + * Converts table definition to CreateTableParams. + */ + public static CreateTableParams toCreateTable(String zoneName, TableDefinition tableDef) { + Set<String> keyColumns = tableDef.keyColumns(); + + List<String> keyColumnsInOrder = tableDef.columns().stream() + .map(ColumnDefinition::name) + .filter(keyColumns::contains) + .collect(Collectors.toList()); + + List<ColumnParams> columnParams = tableDef.columns().stream() + .map(SchemaToCatalogParamsConverter::convert) + .collect(Collectors.toList()); + + return CreateTableParams.builder() + .schemaName(tableDef.schemaName()) + .tableName(tableDef.name()) + .zone(zoneName) + .columns(columnParams) + .primaryKeyColumns(keyColumnsInOrder) + .colocationColumns(tableDef.colocationColumns()) + .build(); + } + + /** + * Convert column to column change. + * + * @param def Column to convert. + * @return Column params. + */ + public static ColumnParams convert(ColumnDefinition def) { + Builder builder = ColumnParams.builder() + .name(def.name()) + .nullable(def.nullable()); + + setType(builder, def.type()); + + assert def.defaultValueDefinition() != null; + + switch (def.defaultValueDefinition().type()) { + case CONSTANT: + ConstantValue constantValue = def.defaultValueDefinition(); + + builder.defaultValue(DefaultValue.constant(constantValue.value())); + + break; + case FUNCTION_CALL: + FunctionCall functionCall = def.defaultValueDefinition(); + + builder.defaultValue(DefaultValue.functionCall(functionCall.functionName())); + + break; + case NULL: + + builder.defaultValue(DefaultValue.constant(null)); + break; + default: + throw new IllegalStateException("Unknown default value definition type [type=" + + def.defaultValueDefinition().type() + ']'); + } + + return builder.build(); + } + + private static org.apache.ignite.sql.ColumnType convert(ColumnType colType) { + switch (colType.typeSpec()) { + case INT8: + return org.apache.ignite.sql.ColumnType.INT8; + case INT16: + return org.apache.ignite.sql.ColumnType.INT16; + case INT32: + return org.apache.ignite.sql.ColumnType.INT32; + case INT64: + return org.apache.ignite.sql.ColumnType.INT64; + case FLOAT: + return org.apache.ignite.sql.ColumnType.FLOAT; + case DOUBLE: + return org.apache.ignite.sql.ColumnType.DOUBLE; + case DECIMAL: + return org.apache.ignite.sql.ColumnType.DECIMAL; + case DATE: + return org.apache.ignite.sql.ColumnType.DATE; + case TIME: + return org.apache.ignite.sql.ColumnType.TIME; + case DATETIME: + return org.apache.ignite.sql.ColumnType.DATETIME; + case TIMESTAMP: + return org.apache.ignite.sql.ColumnType.TIMESTAMP; + case UUID: + return org.apache.ignite.sql.ColumnType.UUID; + case BITMASK: + return org.apache.ignite.sql.ColumnType.BITMASK; + case STRING: + return org.apache.ignite.sql.ColumnType.STRING; + case BYTES: + return org.apache.ignite.sql.ColumnType.BYTE_ARRAY; + case NUMBER: + return org.apache.ignite.sql.ColumnType.NUMBER; + + default: + throw new IllegalArgumentException("Type is not supported: " + colType.typeSpec()); + } + } + + /** + * Convert ColumnType to ColumnTypeChange. + * + * @param builder Column builder. + * @param colType ColumnType. + */ + private static void setType(Builder builder, ColumnType colType) { + builder.type(convert(colType)); + + if (fixSizedTypes.contains(colType.typeSpec())) { + return; + } + + switch (colType.typeSpec()) { + case BITMASK: + case BYTES: + case STRING: + int length = ((ColumnType.VarLenColumnType) colType).length(); + + if (length == 0) { + length = Integer.MAX_VALUE; + } + + builder.length(length); + + return; + case DECIMAL: + ColumnType.DecimalColumnType numColType = (ColumnType.DecimalColumnType) colType; + + builder.precision(numColType.precision()); + builder.scale(numColType.scale()); + + return; + case NUMBER: + ColumnType.NumberColumnType numType = (ColumnType.NumberColumnType) colType; + + builder.precision(numType.precision()); + + return; + case TIME: + case DATETIME: + case TIMESTAMP: + ColumnType.TemporalColumnType temporalColType = (ColumnType.TemporalColumnType) colType; + + builder.precision(temporalColType.precision()); + + return; + default: + throw new IllegalArgumentException("Unknown type " + colType.typeSpec().name()); + } + } +} diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandler.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandler.java index 0bc672a58e..f56848c215 100644 --- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandler.java +++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandler.java @@ -104,7 +104,7 @@ import org.apache.ignite.sql.SqlException; public class DdlCommandHandler { private final DistributionZoneManager distributionZoneManager; - private final TableManager tableManager; + protected final TableManager tableManager; private final IndexManager indexManager; diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandlerWrapper.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandlerWrapper.java index a7a9b7f78e..bb702d4566 100644 --- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandlerWrapper.java +++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandlerWrapper.java @@ -66,40 +66,32 @@ public class DdlCommandHandlerWrapper extends DdlCommandHandler { /** Handles ddl commands. */ @Override public CompletableFuture<Boolean> handle(DdlCommand cmd) { - // Handle command in usual way. - CompletableFuture<Boolean> ddlCommandFuture = super.handle(cmd); - - // Pass supported commands to the Catalog. + // TODO IGNITE-19082 replace TableManager with CatalogManager calls. if (cmd instanceof CreateTableCommand) { - return ddlCommandFuture - .thenCompose(res -> catalogManager.createTable(DdlToCatalogCommandConverter.convert((CreateTableCommand) cmd)) - .handle(handleModificationResult(((CreateTableCommand) cmd).ifTableExists(), TableAlreadyExistsException.class)) - ); + return tableManager.createTableAsync(DdlToCatalogCommandConverter.convert((CreateTableCommand) cmd)) + .handle(handleModificationResult(((CreateTableCommand) cmd).ifTableExists(), TableAlreadyExistsException.class)); } else if (cmd instanceof DropTableCommand) { - return ddlCommandFuture - .thenCompose(res -> catalogManager.dropTable(DdlToCatalogCommandConverter.convert((DropTableCommand) cmd)) - .handle(handleModificationResult(((DropTableCommand) cmd).ifTableExists(), TableNotFoundException.class)) - ); + return tableManager.dropTableAsync(DdlToCatalogCommandConverter.convert((DropTableCommand) cmd)) + .handle(handleModificationResult(((DropTableCommand) cmd).ifTableExists(), TableNotFoundException.class)); } else if (cmd instanceof AlterTableAddCommand) { AlterTableAddCommand addCommand = (AlterTableAddCommand) cmd; - return ddlCommandFuture - .thenCompose(res -> catalogManager.addColumn(DdlToCatalogCommandConverter.convert(addCommand)) - .handle(handleModificationResult(addCommand.ifTableExists(), TableNotFoundException.class)) - ); + return tableManager.alterTableAddColumnAsync(DdlToCatalogCommandConverter.convert(addCommand)) + .handle(handleModificationResult(addCommand.ifTableExists(), TableNotFoundException.class)); } else if (cmd instanceof AlterTableDropCommand) { AlterTableDropCommand dropCommand = (AlterTableDropCommand) cmd; - return ddlCommandFuture - .thenCompose(res -> catalogManager.dropColumn(DdlToCatalogCommandConverter.convert(dropCommand)) - .handle(handleModificationResult(dropCommand.ifTableExists(), TableNotFoundException.class)) - ); + return tableManager.alterTableDropColumnAsync(DdlToCatalogCommandConverter.convert(dropCommand)) + .handle(handleModificationResult(dropCommand.ifTableExists(), TableNotFoundException.class)); } else if (cmd instanceof AlterColumnCommand) { - return ddlCommandFuture - .thenCompose(res -> catalogManager.alterColumn(DdlToCatalogCommandConverter.convert((AlterColumnCommand) cmd)) - .handle(handleModificationResult(((AlterColumnCommand) cmd).ifTableExists(), TableNotFoundException.class)) - ); - } else if (cmd instanceof CreateIndexCommand) { + return catalogManager.alterColumn(DdlToCatalogCommandConverter.convert((AlterColumnCommand) cmd)) + .handle(handleModificationResult(((AlterColumnCommand) cmd).ifTableExists(), TableNotFoundException.class)); + } + + // Handle command in usual way. + CompletableFuture<Boolean> ddlCommandFuture = super.handle(cmd); + + if (cmd instanceof CreateIndexCommand) { return ddlCommandFuture .thenCompose(res -> { AbstractIndexCommandParams params = DdlToCatalogCommandConverter.convert((CreateIndexCommand) cmd); diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlToCatalogCommandConverter.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlToCatalogCommandConverter.java index 22eb89195b..3e958d982b 100644 --- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlToCatalogCommandConverter.java +++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlToCatalogCommandConverter.java @@ -216,6 +216,9 @@ class DdlToCatalogCommandConverter { .name(def.name()) .type(TypeUtils.columnType(def.type())) .nullable(def.nullable()) + .precision(def.precision()) + .scale(def.scale()) + .length(def.precision()) .defaultValue(convert(def.defaultValueDefinition())) .build(); } diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/MockedStructuresTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/MockedStructuresTest.java index ab52605ca2..9aa9471037 100644 --- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/MockedStructuresTest.java +++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/MockedStructuresTest.java @@ -31,6 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.when; @@ -46,6 +48,7 @@ import java.util.function.Consumer; import java.util.function.LongFunction; import org.apache.ignite.internal.baseline.BaselineManager; import org.apache.ignite.internal.catalog.CatalogManager; +import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; import org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager; import org.apache.ignite.internal.cluster.management.topology.api.LogicalTopologySnapshot; import org.apache.ignite.internal.configuration.ConfigurationRegistry; @@ -279,9 +282,13 @@ public class MockedStructuresTest extends IgniteAbstractTest { schemaManager.start(); + //TODO IGNITE-19082 drop mocked catalog manager. catalogManager = mock(CatalogManager.class); + CatalogTableDescriptor descriptor = mock(CatalogTableDescriptor.class); + when(descriptor.id()).thenReturn(1); when(catalogManager.createTable(any())).thenReturn(completedFuture(null)); when(catalogManager.dropTable(any())).thenReturn(completedFuture(null)); + when(catalogManager.table(anyString(), anyLong())).thenReturn(descriptor); cmgMgr = mock(ClusterManagementGroupManager.class); @@ -585,6 +592,7 @@ public class MockedStructuresTest extends IgniteAbstractTest { dataStorageManager, workDir, msm, + catalogManager, schemaManager, null, clock, diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java index 72f9ad055c..375a1fa542 100644 --- a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java +++ b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java @@ -25,6 +25,8 @@ import static java.util.concurrent.CompletableFuture.failedFuture; import static java.util.concurrent.CompletableFuture.runAsync; import static java.util.concurrent.CompletableFuture.supplyAsync; import static java.util.stream.Collectors.toList; +import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME; +import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_ZONE_NAME; import static org.apache.ignite.internal.causality.IncrementalVersionedValue.dependingOn; import static org.apache.ignite.internal.distributionzones.DistributionZonesUtil.getZoneById; import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.partitionAssignments; @@ -34,6 +36,7 @@ import static org.apache.ignite.internal.metastorage.dsl.Operations.put; import static org.apache.ignite.internal.schema.CatalogDescriptorUtils.toTableDescriptor; import static org.apache.ignite.internal.schema.SchemaManager.INITIAL_SCHEMA_VERSION; import static org.apache.ignite.internal.schema.configuration.SchemaConfigurationUtils.findTableView; +import static org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty; import static org.apache.ignite.internal.util.IgniteUtils.inBusyLock; import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination; import static org.apache.ignite.internal.utils.RebalanceUtil.ASSIGNMENTS_SWITCH_REDUCE_PREFIX; @@ -43,6 +46,7 @@ import static org.apache.ignite.internal.utils.RebalanceUtil.extractPartitionNum import static org.apache.ignite.internal.utils.RebalanceUtil.extractTableId; import static org.apache.ignite.internal.utils.RebalanceUtil.pendingPartAssignmentsKey; import static org.apache.ignite.internal.utils.RebalanceUtil.stablePartAssignmentsKey; +import static org.apache.ignite.lang.ErrorGroups.Sql.DROP_IDX_COLUMN_CONSTRAINT_ERR; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import java.io.IOException; @@ -88,6 +92,12 @@ import org.apache.ignite.configuration.notifications.ConfigurationNotificationEv import org.apache.ignite.internal.affinity.AffinityUtils; import org.apache.ignite.internal.affinity.Assignment; import org.apache.ignite.internal.baseline.BaselineManager; +import org.apache.ignite.internal.catalog.CatalogManager; +import org.apache.ignite.internal.catalog.commands.AlterTableAddColumnParams; +import org.apache.ignite.internal.catalog.commands.AlterTableDropColumnParams; +import org.apache.ignite.internal.catalog.commands.ColumnParams; +import org.apache.ignite.internal.catalog.commands.CreateTableParams; +import org.apache.ignite.internal.catalog.commands.DropTableParams; import org.apache.ignite.internal.catalog.descriptors.CatalogDataStorageDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogZoneDescriptor; @@ -125,10 +135,12 @@ import org.apache.ignite.internal.raft.storage.impl.LogStorageFactoryCreator; import org.apache.ignite.internal.replicator.ReplicaManager; import org.apache.ignite.internal.replicator.ReplicaService; import org.apache.ignite.internal.replicator.TablePartitionId; +import org.apache.ignite.internal.schema.CatalogDescriptorUtils; import org.apache.ignite.internal.schema.SchemaManager; import org.apache.ignite.internal.schema.SchemaRegistry; import org.apache.ignite.internal.schema.configuration.ExtendedTableChange; import org.apache.ignite.internal.schema.configuration.GcConfiguration; +import org.apache.ignite.internal.schema.configuration.PrimaryKeyView; import org.apache.ignite.internal.schema.configuration.TableChange; import org.apache.ignite.internal.schema.configuration.TableConfiguration; import org.apache.ignite.internal.schema.configuration.TableView; @@ -184,6 +196,8 @@ import org.apache.ignite.internal.util.PendingComparableValuesTracker; import org.apache.ignite.internal.utils.RebalanceUtil; import org.apache.ignite.internal.vault.VaultManager; import org.apache.ignite.lang.ByteArray; +import org.apache.ignite.lang.ColumnAlreadyExistsException; +import org.apache.ignite.lang.ColumnNotFoundException; import org.apache.ignite.lang.DistributionZoneNotFoundException; import org.apache.ignite.lang.IgniteException; import org.apache.ignite.lang.IgniteExceptionUtils; @@ -198,6 +212,7 @@ import org.apache.ignite.network.ClusterService; import org.apache.ignite.network.MessagingService; import org.apache.ignite.network.TopologyService; import org.apache.ignite.raft.jraft.storage.impl.VolatileRaftMetaStorage; +import org.apache.ignite.sql.SqlException; import org.apache.ignite.table.Table; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -207,8 +222,6 @@ import org.jetbrains.annotations.TestOnly; * Table manager. */ public class TableManager extends Producer<TableEvent, TableEventParameters> implements IgniteTablesInternal, IgniteComponent { - private static final String DEFAULT_SCHEMA_NAME = "PUBLIC"; - private static final long QUERY_DATA_NODES_COUNT_TIMEOUT = TimeUnit.SECONDS.toMillis(3); /** The logger. */ @@ -315,6 +328,9 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp /** Schema manager. */ private final SchemaManager schemaManager; + /** Catalog manager. */ + private final CatalogManager catalogManager; + private final LogStorageFactoryCreator volatileLogStorageFactoryCreator; /** Executor for scheduling retries of a rebalance. */ @@ -390,6 +406,7 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp * @param baselineMgr Baseline manager. * @param txManager Transaction manager. * @param dataStorageMgr Data storage manager. + * @param catalogManager Catalog manager. * @param schemaManager Schema manager. * @param volatileLogStorageFactoryCreator Creator for {@link org.apache.ignite.internal.raft.storage.LogStorageFactory} for * volatile tables. @@ -413,6 +430,7 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp DataStorageManager dataStorageMgr, Path storagePath, MetaStorageManager metaStorageMgr, + CatalogManager catalogManager, SchemaManager schemaManager, LogStorageFactoryCreator volatileLogStorageFactoryCreator, HybridClock clock, @@ -437,6 +455,7 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp this.metaStorageMgr = metaStorageMgr; this.vaultManager = vaultManager; this.schemaManager = schemaManager; + this.catalogManager = catalogManager; this.volatileLogStorageFactoryCreator = volatileLogStorageFactoryCreator; this.clock = clock; this.outgoingSnapshotsManager = outgoingSnapshotsManager; @@ -1343,7 +1362,7 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp } /** - * Completes appropriate future to return result from API {@link TableManager#createTableAsync(String, String, Consumer)}. + * Completes appropriate future to return result from API {@link TableManager#createTableAsync(CreateTableParams)}. * * @param table Table. */ @@ -1473,19 +1492,59 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp * </ul> * @see TableAlreadyExistsException */ + @Deprecated public CompletableFuture<Table> createTableAsync(String name, String zoneName, Consumer<TableChange> tableInitChange) { + throw new UnsupportedOperationException("Method is no longer supported."); + } + + /** + * Creates a new table from parameters. + * + * @param parameters Create table parameters. + * @return Future representing pending completion of the operation. + * @see TableAlreadyExistsException + */ + @Deprecated(forRemoval = true) + public CompletableFuture<Table> createTableAsync(CreateTableParams parameters) { if (!busyLock.enterBusy()) { throw new IgniteException(new NodeStoppingException()); } try { - return createTableAsyncInternal(name, zoneName, tableInitChange); + String tableName = parameters.tableName(); + String zoneName = Objects.requireNonNullElse(parameters.zone(), DEFAULT_ZONE_NAME); + + // Copied from DdlCommandHandler + Consumer<TableChange> tblChanger = tableChange -> { + tableChange.changeColumns(columnsChange -> { + for (var col : parameters.columns()) { + columnsChange.create(col.name(), columnChange -> CatalogDescriptorUtils.convertColumnDefinition(col, columnChange)); + } + }); + + var colocationKeys = parameters.colocationColumns(); + + if (nullOrEmpty(colocationKeys)) { + colocationKeys = parameters.primaryKeyColumns(); + } + + var colocationKeys0 = colocationKeys; + + tableChange.changePrimaryKey(pkChange -> pkChange.changeColumns(parameters.primaryKeyColumns().toArray(String[]::new)) + .changeColocationColumns(colocationKeys0.toArray(String[]::new))); + }; + + return catalogManager.createTable(parameters) + .thenApply(ignore -> catalogManager.table(tableName, Long.MAX_VALUE).id()) + .thenCompose(tableId -> createTableAsyncInternal(tableId, tableName, zoneName, tblChanger)); } finally { busyLock.leaveBusy(); } } - /** See {@link #createTableAsync(String, String, Consumer)} for details. */ + /** See {@link #createTableAsync(CreateTableParams)} for details. */ + @Deprecated(forRemoval = true) private CompletableFuture<Table> createTableAsyncInternal( + int tableId, String name, String zoneName, Consumer<TableChange> tableInitChange @@ -1536,6 +1595,7 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp try { changeTablesConfigurationOnTableCreate( + tableId, name, zoneId, tableInitChange, @@ -1571,12 +1631,14 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp /** * Creates a new table in {@link TablesConfiguration}. * + * @param tableId Table id. * @param name Table name. * @param zoneId Distribution zone id. * @param tableInitChange Table changer. * @param tblFut Future representing pending completion of the table creation. */ private void changeTablesConfigurationOnTableCreate( + int tableId, String name, int zoneId, Consumer<TableChange> tableInitChange, @@ -1597,8 +1659,6 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp var extConfCh = ((ExtendedTableChange) tableChange); - int tableId = tablesChange.globalIdCounter() + 1; - extConfCh.changeId(tableId); tablesChange.changeGlobalIdCounter(tableId); @@ -1641,12 +1701,46 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp * </ul> * @see TableNotFoundException */ + @Deprecated(forRemoval = true) public CompletableFuture<Void> alterTableAsync(String name, Function<TableChange, Boolean> tableChange) { + throw new UnsupportedOperationException("Method is no longer supported."); + } + + /** + * Alters a cluster table and adds columns to the table. + * + * @param params Create column params. + * @return Future representing pending completion of the operation. + * @see TableNotFoundException + */ + @Deprecated + public CompletableFuture<Void> alterTableAddColumnAsync(AlterTableAddColumnParams params) { + if (!busyLock.enterBusy()) { + throw new IgniteException(new NodeStoppingException()); + } + try { + return catalogManager.addColumn(params) + .thenCompose(ignore -> addColumnInternal(params.tableName(), params.columns())); + } finally { + busyLock.leaveBusy(); + } + } + + /** + * Alters a cluster table and drops columns from the table. + * + * @param params Drop column params. + * @return Future representing pending completion of the operation. + * @see TableNotFoundException + */ + @Deprecated + public CompletableFuture<Void> alterTableDropColumnAsync(AlterTableDropColumnParams params) { if (!busyLock.enterBusy()) { throw new IgniteException(new NodeStoppingException()); } try { - return alterTableAsyncInternal(name, tableChange); + return catalogManager.dropColumn(params) + .thenCompose(ignore -> dropColumnInternal(params.tableName(), params.columns())); } finally { busyLock.leaveBusy(); } @@ -1736,18 +1830,33 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp * </ul> * @see TableNotFoundException */ + @Deprecated(forRemoval = true) public CompletableFuture<Void> dropTableAsync(String name) { + throw new UnsupportedOperationException("Method is no longer supported."); + } + + /** + * Drops a table with the name specified. If appropriate table does not be found, a future will be completed with + * {@link TableNotFoundException}. + * + * @param params Drop table parameters. + * @return Future representing pending completion of the operation. + * @see TableNotFoundException + */ + @Deprecated + public CompletableFuture<Void> dropTableAsync(DropTableParams params) { if (!busyLock.enterBusy()) { throw new IgniteException(new NodeStoppingException()); } try { - return dropTableAsyncInternal(name); + return catalogManager.dropTable(params) + .thenCompose(ignore -> dropTableAsyncInternal(params.tableName())); } finally { busyLock.leaveBusy(); } } - /** See {@link #dropTableAsync(String)} for details. */ + /** See {@link #dropTableAsync(DropTableParams)} for details. */ private CompletableFuture<Void> dropTableAsyncInternal(String name) { return tableAsyncInternal(name).thenCompose(tbl -> { // In case of drop it's an optimization that allows not to fire drop-change-closure if there's no such @@ -2718,4 +2827,79 @@ public class TableManager extends Producer<TableEvent, TableEventParameters> imp private CatalogZoneDescriptor getZoneDescriptor(int id) { return toZoneDescriptor(getZoneById(zonesConfig, id).value()); } + + // Copied from DdlCommandHandler + @Deprecated(forRemoval = true) + private CompletableFuture<Void> addColumnInternal(String fullName, List<ColumnParams> columnParams) { + return alterTableAsyncInternal( + fullName, + chng -> { + if (columnParams.isEmpty()) { + return false; + } + + chng.changeColumns(cols -> { + Set<String> colNamesToOrders = new HashSet<>(cols.namedListKeys()); + + columnParams.stream() + .filter(k -> colNamesToOrders.contains(k.name())) + .findAny() + .ifPresent(c -> { + throw new ColumnAlreadyExistsException(c.name()); + }); + + for (ColumnParams col : columnParams) { + cols.create(col.name(), colChg -> CatalogDescriptorUtils.convertColumnDefinition(col, colChg)); + } + }); + + return true; + } + ); + } + + // Copied from DdlCommandHandler + // TODO: IGNITE-19082 Drop unused temporary method. + @Deprecated(forRemoval = true) + private CompletableFuture<Void> dropColumnInternal(String tableName, Set<String> colNames) { + AtomicBoolean ret = new AtomicBoolean(true); + + return alterTableAsyncInternal( + tableName, + chng -> { + chng.changeColumns(cols -> { + ret.set(true); // Reset state if closure have been restarted. + + PrimaryKeyView priKey = chng.primaryKey(); + + Set<String> colNamesToOrders = new HashSet<>(cols.namedListKeys()); + + Set<String> colNames0 = new HashSet<>(); + + Set<String> primaryCols = Set.of(priKey.columns()); + + // Catalog verification passe, so we can omit validation here. + // reportIndexedColumns(tableName, colNames, primaryCols); + + for (String colName : colNames) { + if (!colNamesToOrders.contains(colName)) { + ret.set(false); + + throw new ColumnNotFoundException(DEFAULT_SCHEMA_NAME, tableName, colName); + } else { + colNames0.add(colName); + } + + if (primaryCols.contains(colName)) { + throw new SqlException(DROP_IDX_COLUMN_CONSTRAINT_ERR, IgniteStringFormatter + .format("Can`t delete column, belongs to primary key: [name={}]", colName)); + } + } + + colNames0.forEach(cols::delete); + }); + + return ret.get(); + }); + } } diff --git a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/TableManagerTest.java b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/TableManagerTest.java index 898358beeb..883c0bf771 100644 --- a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/TableManagerTest.java +++ b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/TableManagerTest.java @@ -37,6 +37,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -60,11 +62,13 @@ import java.util.concurrent.Flow.Subscription; import java.util.concurrent.Phaser; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -import java.util.function.Function; import java.util.function.LongFunction; import org.apache.ignite.configuration.NamedListView; import org.apache.ignite.internal.affinity.AffinityUtils; import org.apache.ignite.internal.baseline.BaselineManager; +import org.apache.ignite.internal.catalog.CatalogManager; +import org.apache.ignite.internal.catalog.commands.AlterTableAddColumnParams; +import org.apache.ignite.internal.catalog.commands.DropTableParams; import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogZoneDescriptor; import org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager; @@ -77,8 +81,6 @@ import org.apache.ignite.internal.configuration.testframework.InjectRevisionList import org.apache.ignite.internal.distributionzones.DistributionZoneManager; import org.apache.ignite.internal.distributionzones.configuration.DistributionZonesConfiguration; import org.apache.ignite.internal.hlc.HybridClockImpl; -import org.apache.ignite.internal.logger.IgniteLogger; -import org.apache.ignite.internal.logger.Loggers; import org.apache.ignite.internal.metastorage.MetaStorageManager; import org.apache.ignite.internal.metastorage.dsl.Operation; import org.apache.ignite.internal.raft.Loza; @@ -93,10 +95,10 @@ import org.apache.ignite.internal.schema.SchemaManager; import org.apache.ignite.internal.schema.SchemaUtils; import org.apache.ignite.internal.schema.configuration.ExtendedTableChange; import org.apache.ignite.internal.schema.configuration.GcConfiguration; -import org.apache.ignite.internal.schema.configuration.TableChange; import org.apache.ignite.internal.schema.configuration.TableView; import org.apache.ignite.internal.schema.configuration.TablesConfiguration; import org.apache.ignite.internal.schema.testutils.SchemaConfigurationConverter; +import org.apache.ignite.internal.schema.testutils.SchemaToCatalogParamsConverter; import org.apache.ignite.internal.schema.testutils.builder.SchemaBuilders; import org.apache.ignite.internal.schema.testutils.definition.ColumnType; import org.apache.ignite.internal.schema.testutils.definition.TableDefinition; @@ -143,8 +145,6 @@ import org.mockito.quality.Strictness; @ExtendWith({MockitoExtension.class, ConfigurationExtension.class}) @MockitoSettings(strictness = Strictness.LENIENT) public class TableManagerTest extends IgniteAbstractTest { - private static final IgniteLogger LOG = Loggers.forClass(TableManagerTest.class); - /** The name of the table which is preconfigured. */ private static final String PRECONFIGURED_TABLE_NAME = "T1"; @@ -388,7 +388,7 @@ public class TableManagerTest extends IgniteAbstractTest { TableManager tableManager = tblManagerFut.join(); - await(tableManager.dropTableAsync(DYNAMIC_TABLE_FOR_DROP_NAME)); + await(tableManager.dropTableAsync(DropTableParams.builder().schemaName("PUBLIC").tableName(DYNAMIC_TABLE_FOR_DROP_NAME).build())); verify(mvTableStorage).destroy(); verify(txStateTableStorage).destroy(); @@ -413,33 +413,33 @@ public class TableManagerTest extends IgniteAbstractTest { createDistributionZone(); - Consumer<TableChange> createTableChange = (TableChange change) -> - SchemaConfigurationConverter.convert(SchemaBuilders.tableBuilder("PUBLIC", DYNAMIC_TABLE_FOR_DROP_NAME).columns( - SchemaBuilders.column("key", ColumnType.INT64).build(), - SchemaBuilders.column("val", ColumnType.INT64).asNullable(true).build() - ).withPrimaryKey("key").build(), change); - - Function<TableChange, Boolean> addColumnChange = (TableChange change) -> { - change.changeColumns(cols -> { - int colIdx = change.columns().namedListKeys().stream().mapToInt(Integer::parseInt).max().getAsInt() + 1; - - cols.create(String.valueOf(colIdx), - colChg -> SchemaConfigurationConverter.convert(SchemaBuilders.column("name", ColumnType.string()).build(), - colChg)); - - }); + TableDefinition tableDef = SchemaBuilders.tableBuilder("PUBLIC", DYNAMIC_TABLE_FOR_DROP_NAME) + .columns( + SchemaBuilders.column("key", ColumnType.INT64).build(), + SchemaBuilders.column("val", ColumnType.INT64).asNullable(true).build() + ) + .withPrimaryKey("key") + .build(); - return true; - }; + AlterTableAddColumnParams addColumnParams = AlterTableAddColumnParams.builder() + .schemaName("PUBLIC") + .tableName(DYNAMIC_TABLE_FOR_DROP_NAME) + .columns(List.of( + SchemaToCatalogParamsConverter.convert(SchemaBuilders.column("name", ColumnType.string()).build()) + )) + .build(); TableManager igniteTables = tableManager; assertThrows(IgniteException.class, - () -> igniteTables.createTableAsync(DYNAMIC_TABLE_FOR_DROP_NAME, ZONE_NAME, createTableChange)); + () -> igniteTables.createTableAsync(SchemaToCatalogParamsConverter.toCreateTable(ZONE_NAME, tableDef))); - assertThrows(IgniteException.class, () -> igniteTables.alterTableAsync(DYNAMIC_TABLE_FOR_DROP_NAME, addColumnChange)); + assertThrows(IgniteException.class, () -> igniteTables.alterTableAddColumnAsync(addColumnParams)); - assertThrows(IgniteException.class, () -> igniteTables.dropTableAsync(DYNAMIC_TABLE_FOR_DROP_NAME)); + assertThrows(IgniteException.class, () -> igniteTables.dropTableAsync(DropTableParams.builder() + .schemaName(tableDef.schemaName()) + .tableName(tableDef.name()) + .build())); assertThrows(IgniteException.class, () -> igniteTables.tables()); assertThrows(IgniteException.class, () -> igniteTables.tablesAsync()); @@ -632,8 +632,9 @@ public class TableManagerTest extends IgniteAbstractTest { assertNotNull(table); assertThrows(RuntimeException.class, - () -> await(tblManagerFut.join().createTableAsync(DYNAMIC_TABLE_NAME, ZONE_NAME, - tblCh -> SchemaConfigurationConverter.convert(scmTbl, tblCh)))); + () -> await(tblManagerFut.join().createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(ZONE_NAME, scmTbl) + ))); assertSame(table, tblManagerFut.join().table(scmTbl.name())); } @@ -822,8 +823,8 @@ public class TableManagerTest extends IgniteAbstractTest { createDistributionZone(); - CompletableFuture<Table> tbl2Fut = tableManager.createTableAsync(tableDefinition.name(), ZONE_NAME, - tblCh -> SchemaConfigurationConverter.convert(tableDefinition, tblCh) + CompletableFuture<Table> tbl2Fut = tableManager.createTableAsync( + SchemaToCatalogParamsConverter.toCreateTable(ZONE_NAME, tableDefinition) ); assertTrue(createTblLatch.await(10, TimeUnit.SECONDS)); @@ -857,6 +858,14 @@ public class TableManagerTest extends IgniteAbstractTest { when(vaultManager.get(any(ByteArray.class))).thenReturn(completedFuture(null)); when(vaultManager.put(any(ByteArray.class), any(byte[].class))).thenReturn(completedFuture(null)); + //TODO IGNITE-19082 drop mocked catalog manager. + CatalogManager catalogManager = mock(CatalogManager.class); + CatalogTableDescriptor tableDescriptor = mock(CatalogTableDescriptor.class); + when(catalogManager.createTable(any())).thenReturn(completedFuture(null)); + when(catalogManager.dropTable(any())).thenReturn(completedFuture(null)); + when(catalogManager.table(anyString(), anyLong())).thenReturn(tableDescriptor); + when(tableDescriptor.id()).thenReturn(1); + TableManager tableManager = new TableManager( "test", revisionUpdater, @@ -874,6 +883,7 @@ public class TableManagerTest extends IgniteAbstractTest { dsm = createDataStorageManager(configRegistry, workDir, storageEngineConfig), workDir, msm, + catalogManager, sm = new SchemaManager(revisionUpdater, tblsCfg, msm), budgetView -> new LocalLogStorageFactory(), new HybridClockImpl(),