use of org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder 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.builder.SortedIndexDefinitionBuilder in project ignite-3 by apache.
the class DdlCommandHandler method handleCreateIndex.
/**
* Handles create index command.
*/
private void handleCreateIndex(CreateIndexCommand cmd) {
// Only sorted idx for now.
SortedIndexDefinitionBuilder idx = SchemaBuilders.sortedIndex(cmd.indexName());
for (Pair<String, Boolean> idxInfo : cmd.columns()) {
SortedIndexColumnBuilder idx0 = idx.addIndexColumn(idxInfo.getFirst());
if (idxInfo.getSecond()) {
idx0.desc();
}
idx0.done();
}
String fullName = TableDefinitionImpl.canonicalName(IgniteObjectName.quote(cmd.schemaName()), IgniteObjectName.quote(cmd.tableName()));
tableManager.alterTable(fullName, chng -> chng.changeIndices(idxes -> {
if (idxes.get(cmd.indexName()) != null) {
if (!cmd.ifIndexNotExists()) {
throw new IndexAlreadyExistsException(cmd.indexName());
} else {
return;
}
}
idxes.create(cmd.indexName(), tableIndexChange -> convert(idx.build(), tableIndexChange));
}));
}
use of org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder 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