Search in sources :

Example 1 with CreateIndexCommand

use of org.apache.ignite.internal.sql.engine.prepare.ddl.CreateIndexCommand 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 NamedListView (org.apache.ignite.configuration.NamedListView)1 ColumnView (org.apache.ignite.configuration.schemas.table.ColumnView)1 PrimaryKeyView (org.apache.ignite.configuration.schemas.table.PrimaryKeyView)1 TableChange (org.apache.ignite.configuration.schemas.table.TableChange)1 SchemaConfigurationConverter.convert (org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter.convert)1 TableDefinitionImpl (org.apache.ignite.internal.schema.definition.TableDefinitionImpl)1 AbstractTableDdlCommand (org.apache.ignite.internal.sql.engine.prepare.ddl.AbstractTableDdlCommand)1 AlterTableAddCommand (org.apache.ignite.internal.sql.engine.prepare.ddl.AlterTableAddCommand)1 AlterTableDropCommand (org.apache.ignite.internal.sql.engine.prepare.ddl.AlterTableDropCommand)1 ColumnDefinition (org.apache.ignite.internal.sql.engine.prepare.ddl.ColumnDefinition)1 CreateIndexCommand (org.apache.ignite.internal.sql.engine.prepare.ddl.CreateIndexCommand)1 CreateTableCommand (org.apache.ignite.internal.sql.engine.prepare.ddl.CreateTableCommand)1