Search in sources :

Example 1 with SortedIndexDefinition

use of org.apache.ignite.schema.definition.index.SortedIndexDefinition 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 SortedIndexDefinition

use of org.apache.ignite.schema.definition.index.SortedIndexDefinition in project ignite-3 by apache.

the class SchemaConfigurationConverterTest method testUniqIndex.

/**
 * Add/remove index on primary key into configuration and read it back.
 */
@Test
public void testUniqIndex() throws Exception {
    SortedIndexDefinition idx = SchemaBuilders.sortedIndex("pk_sorted").addIndexColumn("COL1").desc().done().unique(true).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("PK_SORTED", idx2.name());
    assertEquals("SORTED", idx2.type());
    assertEquals(idx.columns().stream().map(IndexColumnDefinition::name).collect(Collectors.toList()), idx2.columns().stream().map(IndexColumnDefinition::name).collect(Collectors.toList()));
    assertTrue(idx2.unique());
}
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) IndexColumnDefinition(org.apache.ignite.schema.definition.index.IndexColumnDefinition) SortedIndexDefinition(org.apache.ignite.schema.definition.index.SortedIndexDefinition) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with SortedIndexDefinition

use of org.apache.ignite.schema.definition.index.SortedIndexDefinition in project ignite-3 by apache.

the class SchemaConfigurationConverterTest method testUniqueIndexDetection.

/**
 * Detect an index containing affinity key as unique one.
 */
@Disabled("https://issues.apache.org/jira/browse/IGNITE-15483")
@Test
public void testUniqueIndexDetection() throws Exception {
    SortedIndexDefinition idx = SchemaBuilders.sortedIndex("uniq_sorted").addIndexColumn("A").done().addIndexColumn("COL1").desc().done().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("uniq_sorted", idx2.name());
    assertEquals("SORTED", idx2.type());
    assertTrue(idx2.unique());
    assertEquals(2, idx2.columns().size());
    assertEquals("A", idx2.columns().get(0).name());
    assertEquals("COL1", 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) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with SortedIndexDefinition

use of org.apache.ignite.schema.definition.index.SortedIndexDefinition in project ignite-3 by apache.

the class SchemaConfigurationConverter method convert.

/**
 * Convert TableIndex to TableIndexChange.
 *
 * @param idx    TableIndex.
 * @param idxChg TableIndexChange to fulfill.
 * @return TableIndexChange to get result from.
 */
public static TableIndexChange convert(IndexDefinition idx, TableIndexChange idxChg) {
    idxChg.changeName(idx.name());
    switch(idx.type().toUpperCase()) {
        case HASH_INDEX_TYPE:
            HashIndexDefinition hashIdx = (HashIndexDefinition) idx;
            String[] colNames = hashIdx.columns().stream().map(IndexColumnDefinition::name).toArray(String[]::new);
            return idxChg.convert(HashIndexChange.class).changeColNames(colNames);
        case PARTIAL_INDEX_TYPE:
            PartialIndexDefinition partIdx = (PartialIndexDefinition) idx;
            return idxChg.changeUniq(partIdx.unique()).convert(PartialIndexChange.class).changeExpr(partIdx.expr()).changeColumns(colsChg -> {
                for (SortedIndexColumnDefinition col : partIdx.columns()) {
                    colsChg.create(col.name(), colInit -> convert(col, colInit));
                }
            });
        case SORTED_INDEX_TYPE:
            SortedIndexDefinition sortIdx = (SortedIndexDefinition) idx;
            return idxChg.changeUniq(sortIdx.unique()).convert(SortedIndexChange.class).changeColumns(colsInit -> {
                for (SortedIndexColumnDefinition col : sortIdx.columns()) {
                    colsInit.create(col.name(), colInit -> convert(col, colInit));
                }
            });
        default:
            throw new IllegalArgumentException("Unknown index type " + idx.type());
    }
}
Also used : HashIndexChange(org.apache.ignite.configuration.schemas.table.HashIndexChange) HashIndexDefinition(org.apache.ignite.schema.definition.index.HashIndexDefinition) SortedIndexDefinition(org.apache.ignite.schema.definition.index.SortedIndexDefinition) PartialIndexDefinition(org.apache.ignite.schema.definition.index.PartialIndexDefinition) SortedIndexChange(org.apache.ignite.configuration.schemas.table.SortedIndexChange) SortedIndexColumnDefinition(org.apache.ignite.schema.definition.index.SortedIndexColumnDefinition)

Example 5 with SortedIndexDefinition

use of org.apache.ignite.schema.definition.index.SortedIndexDefinition 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

SortedIndexDefinition (org.apache.ignite.schema.definition.index.SortedIndexDefinition)5 SortedIndexDefinitionBuilder (org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder)4 HashIndexDefinition (org.apache.ignite.schema.definition.index.HashIndexDefinition)4 PartialIndexDefinition (org.apache.ignite.schema.definition.index.PartialIndexDefinition)4 Collection (java.util.Collection)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 ExecutionException (java.util.concurrent.ExecutionException)3 Collectors (java.util.stream.Collectors)3 DISTRIBUTED (org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED)3 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)3 RocksDbDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema)3 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)3 PartialIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema)3 SortedIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema)3 TableConfiguration (org.apache.ignite.configuration.schemas.table.TableConfiguration)3 TableValidator (org.apache.ignite.configuration.schemas.table.TableValidator)3 TablesConfiguration (org.apache.ignite.configuration.schemas.table.TablesConfiguration)3