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());
}
}
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());
}
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());
}
Aggregations