Search in sources :

Example 1 with HashIndexDefinition

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

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

the class SchemaConfigurationConverterTest method testConvertHashIndex.

/**
 * Add/remove HashIndex into configuration and read it back.
 */
@Test
public void testConvertHashIndex() throws Exception {
    HashIndexDefinitionBuilder builder = SchemaBuilders.hashIndex("testHI").withColumns("A", "B", "C").withHints(Collections.singletonMap("param", "value"));
    HashIndexDefinition idx = builder.build();
    getTbl().change(ch -> SchemaConfigurationConverter.addIndex(idx, ch)).get();
    TableDefinition tbl = SchemaConfigurationConverter.convert(getTbl().value());
    HashIndexDefinition idx2 = (HashIndexDefinition) getIdx(idx.name(), tbl.indices());
    assertNotNull(idx2);
    assertEquals("HASH", idx2.type());
    assertEquals(3, idx2.columns().size());
}
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) HashIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.HashIndexDefinitionBuilder) HashIndexDefinition(org.apache.ignite.schema.definition.index.HashIndexDefinition) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with HashIndexDefinition

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

the class HashIndexDefinitionBuilderTest method testBuild.

/**
 * Build index and check its parameters.
 */
@Test
public void testBuild() {
    HashIndexDefinitionBuilder builder = SchemaBuilders.hashIndex("testHI").withColumns("A", "B", "C").withHints(Collections.singletonMap("param", "value"));
    HashIndexDefinition idx = builder.build();
    assertEquals("TESTHI", idx.name());
    assertEquals(3, idx.columns().size());
}
Also used : HashIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.HashIndexDefinitionBuilder) HashIndexDefinition(org.apache.ignite.schema.definition.index.HashIndexDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

HashIndexDefinition (org.apache.ignite.schema.definition.index.HashIndexDefinition)3 HashIndexDefinitionBuilder (org.apache.ignite.schema.definition.builder.HashIndexDefinitionBuilder)2 PartialIndexDefinition (org.apache.ignite.schema.definition.index.PartialIndexDefinition)2 SortedIndexDefinition (org.apache.ignite.schema.definition.index.SortedIndexDefinition)2 Test (org.junit.jupiter.api.Test)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)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 HashIndexChange (org.apache.ignite.configuration.schemas.table.HashIndexChange)1 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)1 PartialIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema)1 SortedIndexChange (org.apache.ignite.configuration.schemas.table.SortedIndexChange)1 SortedIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema)1