use of org.apache.ignite.lang.IndexAlreadyExistsException 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.lang.IndexAlreadyExistsException in project ignite-3 by apache.
the class ItTablesApiTest method addIndex.
/**
* Adds a column.
*
* @param node Cluster node.
* @param schemaName Schema name.
* @param shortTableName Table name.
*/
protected void addIndex(Ignite node, String schemaName, String shortTableName) {
IndexDefinition idx = SchemaBuilders.hashIndex("testHI").withColumns("valInt", "valStr").build();
node.tables().alterTable(schemaName + "." + shortTableName, chng -> chng.changeIndices(idxes -> {
if (idxes.get(idx.name()) != null) {
log.info("Index already exists [naem={}]", idx.name());
throw new IndexAlreadyExistsException(idx.name());
}
idxes.create(idx.name(), tableIndexChange -> convert(idx, tableIndexChange));
}));
}
Aggregations