Search in sources :

Example 1 with SortedIndexColumnDefinition

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

Aggregations

HashIndexChange (org.apache.ignite.configuration.schemas.table.HashIndexChange)1 SortedIndexChange (org.apache.ignite.configuration.schemas.table.SortedIndexChange)1 HashIndexDefinition (org.apache.ignite.schema.definition.index.HashIndexDefinition)1 PartialIndexDefinition (org.apache.ignite.schema.definition.index.PartialIndexDefinition)1 SortedIndexColumnDefinition (org.apache.ignite.schema.definition.index.SortedIndexColumnDefinition)1 SortedIndexDefinition (org.apache.ignite.schema.definition.index.SortedIndexDefinition)1