use of org.apache.ignite.schema.definition.index.PartialIndexDefinition in project ignite-3 by apache.
the class SchemaConfigurationConverterTest method testPartialIndex.
/**
* Add/remove PartialIndex into configuration and read it back.
*/
@Test
public void testPartialIndex() throws Exception {
PartialIndexDefinitionBuilder builder = SchemaBuilders.partialIndex("TEST");
builder.addIndexColumn("A").done();
builder.withExpression("WHERE A > 0");
PartialIndexDefinition idx = builder.build();
getTbl().change(ch -> SchemaConfigurationConverter.addIndex(idx, ch)).get();
TableDefinition tbl = SchemaConfigurationConverter.convert(getTbl().value());
PartialIndexDefinition idx2 = (PartialIndexDefinition) getIdx(idx.name(), tbl.indices());
assertNotNull(idx2);
assertEquals("PARTIAL", idx2.type());
assertEquals(idx.columns().size(), idx2.columns().size());
}
use of org.apache.ignite.schema.definition.index.PartialIndexDefinition 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.PartialIndexDefinition in project ignite-3 by apache.
the class PartialIndexDefinitionBuilderTest method testPartialIndexCreate.
/**
* Test partial index parameters.
*/
@Test
public void testPartialIndexCreate() {
PartialIndexDefinitionBuilder builder = SchemaBuilders.partialIndex("TEST");
builder.addIndexColumn("A").done();
builder.withExpression("WHERE A > 0");
PartialIndexDefinition idx = builder.build();
assertEquals(1, idx.columns().size());
assertEquals("WHERE A > 0", idx.expr());
}
Aggregations