Search in sources :

Example 1 with SortedIndexDefinitionBuilder

use of org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder in project ignite-3 by apache.

the class SortedIndexDefinitionBuilderTest method testBuild.

/**
 * Build sorted index and check it's parameters.
 */
@Test
public void testBuild() {
    SortedIndexDefinitionBuilder builder = SchemaBuilders.sortedIndex("SIDX");
    builder.addIndexColumn("A").asc().done();
    builder.addIndexColumn("B").desc().done();
    SortedIndexDefinition idx = builder.build();
    assertFalse(idx.unique());
    assertEquals(2, idx.indexedColumns().size());
    assertEquals(SortOrder.ASC, idx.columns().get(0).sortOrder());
    assertEquals(SortOrder.DESC, idx.columns().get(1).sortOrder());
}
Also used : SortedIndexDefinition(org.apache.ignite.schema.definition.index.SortedIndexDefinition) SortedIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with SortedIndexDefinitionBuilder

use of org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder 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 3 with SortedIndexDefinitionBuilder

use of org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder in project ignite-3 by apache.

the class SchemaConfigurationConverterTest method testConvertSortedIndex.

/**
 * Add/remove SortedIndex into configuration and read it back.
 */
@Test
public void testConvertSortedIndex() throws Exception {
    SortedIndexDefinitionBuilder builder = SchemaBuilders.sortedIndex("SIDX");
    builder.addIndexColumn("A").asc().done();
    builder.addIndexColumn("B").desc().done();
    SortedIndexDefinition idx = builder.build();
    getTbl().change(ch -> SchemaConfigurationConverter.addIndex(idx, ch)).get();
    TableDefinition tbl = SchemaConfigurationConverter.convert(getTbl().value());
    SortedIndexDefinition idx2 = (SortedIndexDefinition) getIdx(idx.name(), tbl.indices());
    assertNotNull(idx2);
    assertEquals("SORTED", idx2.type());
    assertEquals(2, idx2.columns().size());
    assertEquals("A", idx2.columns().get(0).name());
    assertEquals("B", idx2.columns().get(1).name());
    assertEquals(SortOrder.ASC, idx2.columns().get(0).sortOrder());
    assertEquals(SortOrder.DESC, idx2.columns().get(1).sortOrder());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) HashIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema) SortedIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach) IndexColumnDefinition(org.apache.ignite.schema.definition.index.IndexColumnDefinition) SortOrder(org.apache.ignite.schema.definition.index.SortOrder) HashIndexDefinition(org.apache.ignite.schema.definition.index.HashIndexDefinition) DISTRIBUTED(org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) PartialIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema) SortedIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema) HashIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.HashIndexDefinitionBuilder) Disabled(org.junit.jupiter.api.Disabled) Map(java.util.Map) RocksDbDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema) SortedIndexDefinition(org.apache.ignite.schema.definition.index.SortedIndexDefinition) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexDefinition(org.apache.ignite.schema.definition.index.IndexDefinition) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Collection(java.util.Collection) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) PartialIndexDefinition(org.apache.ignite.schema.definition.index.PartialIndexDefinition) Set(java.util.Set) PartialIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.PartialIndexDefinitionBuilder) TableValidator(org.apache.ignite.configuration.schemas.table.TableValidator) ColumnType(org.apache.ignite.schema.definition.ColumnType) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Collections(java.util.Collections) SortedIndexDefinition(org.apache.ignite.schema.definition.index.SortedIndexDefinition) SortedIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

SortedIndexDefinitionBuilder (org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder)3 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 Consumer (java.util.function.Consumer)1 NamedListView (org.apache.ignite.configuration.NamedListView)1 DISTRIBUTED (org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED)1 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)1 RocksDbDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema)1 ColumnView (org.apache.ignite.configuration.schemas.table.ColumnView)1 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)1 PartialIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema)1