Search in sources :

Example 1 with IndexAlreadyExistsException

use of org.apache.ignite.lang.IndexAlreadyExistsException in project ignite-3 by apache.

the class DdlCommandHandler method handleCreateIndex.

/**
 * Handles create index command.
 */
private void handleCreateIndex(CreateIndexCommand cmd) {
    // Only sorted idx for now.
    SortedIndexDefinitionBuilder idx = SchemaBuilders.sortedIndex(cmd.indexName());
    for (Pair<String, Boolean> idxInfo : cmd.columns()) {
        SortedIndexColumnBuilder idx0 = idx.addIndexColumn(idxInfo.getFirst());
        if (idxInfo.getSecond()) {
            idx0.desc();
        }
        idx0.done();
    }
    String fullName = TableDefinitionImpl.canonicalName(IgniteObjectName.quote(cmd.schemaName()), IgniteObjectName.quote(cmd.tableName()));
    tableManager.alterTable(fullName, chng -> chng.changeIndices(idxes -> {
        if (idxes.get(cmd.indexName()) != null) {
            if (!cmd.ifIndexNotExists()) {
                throw new IndexAlreadyExistsException(cmd.indexName());
            } else {
                return;
            }
        }
        idxes.create(cmd.indexName(), tableIndexChange -> convert(idx.build(), tableIndexChange));
    }));
}
Also used : SortedIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder) Pair(org.apache.ignite.internal.util.Pair) CollectionUtils.nullOrEmpty(org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty) SchemaConfigurationConverter.convert(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter.convert) IgniteException(org.apache.ignite.lang.IgniteException) ColumnDefinition(org.apache.ignite.internal.sql.engine.prepare.ddl.ColumnDefinition) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ColumnDefinitionBuilder(org.apache.ignite.schema.definition.builder.ColumnDefinitionBuilder) DropTableCommand(org.apache.ignite.internal.sql.engine.prepare.ddl.DropTableCommand) Map(java.util.Map) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) PrimaryKeyView(org.apache.ignite.configuration.schemas.table.PrimaryKeyView) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) PrimaryKeyDefinitionBuilder(org.apache.ignite.schema.definition.builder.PrimaryKeyDefinitionBuilder) TableDefinitionImpl(org.apache.ignite.internal.schema.definition.TableDefinitionImpl) TableManager(org.apache.ignite.internal.table.distributed.TableManager) ColumnView(org.apache.ignite.configuration.schemas.table.ColumnView) SortedIndexColumnBuilder(org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder.SortedIndexColumnBuilder) NamedListView(org.apache.ignite.configuration.NamedListView) AbstractTableDdlCommand(org.apache.ignite.internal.sql.engine.prepare.ddl.AbstractTableDdlCommand) CreateIndexCommand(org.apache.ignite.internal.sql.engine.prepare.ddl.CreateIndexCommand) Set(java.util.Set) IgniteObjectName(org.apache.ignite.internal.util.IgniteObjectName) Collectors(java.util.stream.Collectors) Commons(org.apache.ignite.internal.sql.engine.util.Commons) AlterTableDropCommand(org.apache.ignite.internal.sql.engine.prepare.ddl.AlterTableDropCommand) Consumer(java.util.function.Consumer) DdlCommand(org.apache.ignite.internal.sql.engine.prepare.ddl.DdlCommand) CreateTableCommand(org.apache.ignite.internal.sql.engine.prepare.ddl.CreateTableCommand) List(java.util.List) IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) AlterTableAddCommand(org.apache.ignite.internal.sql.engine.prepare.ddl.AlterTableAddCommand) DropIndexCommand(org.apache.ignite.internal.sql.engine.prepare.ddl.DropIndexCommand) ColumnAlreadyExistsException(org.apache.ignite.lang.ColumnAlreadyExistsException) ColumnNotFoundException(org.apache.ignite.lang.ColumnNotFoundException) IndexAlreadyExistsException(org.apache.ignite.lang.IndexAlreadyExistsException) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) IgniteStringFormatter(org.apache.ignite.lang.IgniteStringFormatter) TableChange(org.apache.ignite.configuration.schemas.table.TableChange) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IndexAlreadyExistsException(org.apache.ignite.lang.IndexAlreadyExistsException) SortedIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder) SortedIndexColumnBuilder(org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder.SortedIndexColumnBuilder)

Example 2 with IndexAlreadyExistsException

use of org.apache.ignite.lang.IndexAlreadyExistsException in project ignite-3 by apache.

the class ItTablesApiTest method addIndex.

/**
 * Adds a column.
 *
 * @param node           Cluster node.
 * @param schemaName     Schema name.
 * @param shortTableName Table name.
 */
protected void addIndex(Ignite node, String schemaName, String shortTableName) {
    IndexDefinition idx = SchemaBuilders.hashIndex("testHI").withColumns("valInt", "valStr").build();
    node.tables().alterTable(schemaName + "." + shortTableName, chng -> chng.changeIndices(idxes -> {
        if (idxes.get(idx.name()) != null) {
            log.info("Index already exists [naem={}]", idx.name());
            throw new IndexAlreadyExistsException(idx.name());
        }
        idxes.create(idx.name(), tableIndexChange -> convert(idx, tableIndexChange));
    }));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IntStream(java.util.stream.IntStream) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IgniteTablesInternal(org.apache.ignite.internal.table.IgniteTablesInternal) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) SchemaConfigurationConverter.convert(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter.convert) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) WatchListenerInhibitor.metastorageEventsInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor.metastorageEventsInhibitor) ArrayList(java.util.ArrayList) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) TableImpl(org.apache.ignite.internal.table.TableImpl) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) IndexDefinition(org.apache.ignite.schema.definition.index.IndexDefinition) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) ColumnType(org.apache.ignite.schema.definition.ColumnType) Collectors(java.util.stream.Collectors) TestInfo(org.junit.jupiter.api.TestInfo) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) IgnitionManager(org.apache.ignite.IgnitionManager) IgniteTestUtils(org.apache.ignite.internal.testframework.IgniteTestUtils) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ColumnAlreadyExistsException(org.apache.ignite.lang.ColumnAlreadyExistsException) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) IndexAlreadyExistsException(org.apache.ignite.lang.IndexAlreadyExistsException) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Table(org.apache.ignite.table.Table) ItUtils(org.apache.ignite.internal.ItUtils) Tuple(org.apache.ignite.table.Tuple) IndexDefinition(org.apache.ignite.schema.definition.index.IndexDefinition) IndexAlreadyExistsException(org.apache.ignite.lang.IndexAlreadyExistsException)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 SchemaConfigurationConverter.convert (org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter.convert)2 IgniteUtils (org.apache.ignite.internal.util.IgniteUtils)2 ColumnAlreadyExistsException (org.apache.ignite.lang.ColumnAlreadyExistsException)2 IndexAlreadyExistsException (org.apache.ignite.lang.IndexAlreadyExistsException)2 TableAlreadyExistsException (org.apache.ignite.lang.TableAlreadyExistsException)2 TableNotFoundException (org.apache.ignite.lang.TableNotFoundException)2 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1