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