use of org.apache.ignite.schema.definition.index.IndexDefinition in project ignite-3 by apache.
the class SchemaConfigurationConverter method convert.
/**
* Convert table configuration view to table schema.
*
* @param tblView TableView to convert.
* @return Table schema.
*/
public static TableDefinitionImpl convert(TableView tblView) {
String canonicalName = tblView.name();
int sepPos = canonicalName.indexOf('.');
String schemaName = canonicalName.substring(0, sepPos);
String tableName = canonicalName.substring(sepPos + 1);
NamedListView<? extends ColumnView> colsView = tblView.columns();
var columns = new LinkedHashMap<String, ColumnDefinition>(capacity(colsView.size()));
for (String key : colsView.namedListKeys()) {
ColumnView colView = colsView.get(key);
if (colView != null) {
ColumnDefinition definition = convert(colView);
columns.put(definition.name(), definition);
}
}
NamedListView<? extends TableIndexView> idxsView = tblView.indices();
var indices = new HashMap<String, IndexDefinition>(capacity(idxsView.size()));
for (String key : idxsView.namedListKeys()) {
IndexDefinition definition = convert(idxsView.get(key));
indices.put(definition.name(), definition);
}
PrimaryKeyDefinition primaryKey = convert(tblView.primaryKey());
return new TableDefinitionImpl(schemaName, tableName, columns, primaryKey, indices);
}
use of org.apache.ignite.schema.definition.index.IndexDefinition in project ignite-3 by apache.
the class SchemaConfigurationConverter method convert.
/**
* Convert table schema to table changer.
*
* @param tbl Table schema to convert.
* @param tblChg Change to fulfill.
* @return TableChange to get result from.
*/
public static TableChange convert(TableDefinition tbl, TableChange tblChg) {
tblChg.changeName(tbl.canonicalName());
tblChg.changeIndices(idxsChg -> {
for (IndexDefinition idx : tbl.indices()) {
idxsChg.create(idx.name(), idxInit -> convert(idx, idxInit));
}
});
tblChg.changeColumns(colsChg -> {
for (ColumnDefinition col : tbl.columns()) {
colsChg.create(col.name(), colChg -> convert(col, colChg));
}
});
tblChg.changePrimaryKey(pkCng -> {
pkCng.changeColumns(tbl.keyColumns().toArray(String[]::new)).changeColocationColumns(tbl.colocationColumns().toArray(String[]::new));
});
return tblChg;
}
use of org.apache.ignite.schema.definition.index.IndexDefinition 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));
}));
}
use of org.apache.ignite.schema.definition.index.IndexDefinition in project ignite-3 by apache.
the class ItTablesApiTest method addIndexIfNotExists.
/**
* Creates a table if it does not exist.
*
* @param node Cluster node.
* @param schemaName Schema name.
* @param shortTableName Table name.
*/
protected void addIndexIfNotExists(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) {
idxes.create(idx.name(), tableIndexChange -> convert(idx, tableIndexChange));
} else {
log.info("Index already exists [naem={}]", idx.name());
}
}));
}
Aggregations