use of org.apache.ignite.schema.definition.PrimaryKeyDefinition in project ignite-3 by apache.
the class PrimaryKeyDefinitionDefinitionBuilderTest method testPrimaryKeyWithColocationColumns.
/**
* Test primary key parameters.
*/
@Test
public void testPrimaryKeyWithColocationColumns() {
PrimaryKeyDefinitionBuilder builder = SchemaBuilders.primaryKey();
builder.withColumns("A", "B", "C").withColocationColumns("B").build();
PrimaryKeyDefinition idx = builder.build();
assertEquals(3, idx.columns().size());
assertEquals(1, idx.colocationColumns().size());
assertTrue(idx.columns().containsAll(List.of("A", "B", "C")));
assertTrue(idx.colocationColumns().contains("B"));
assertFalse(idx.colocationColumns().contains("A"));
assertFalse(idx.colocationColumns().contains("C"));
}
use of org.apache.ignite.schema.definition.PrimaryKeyDefinition in project ignite-3 by apache.
the class PrimaryKeyDefinitionDefinitionBuilderTest method testPrimaryKey.
/**
* Test primary key parameters.
*/
@Test
public void testPrimaryKey() {
PrimaryKeyDefinitionBuilder builder = SchemaBuilders.primaryKey();
builder.withColumns("A", "B", "C").build();
PrimaryKeyDefinition idx = builder.build();
assertEquals(3, idx.columns().size());
assertEquals(3, idx.colocationColumns().size());
assertTrue(idx.columns().containsAll(List.of("A", "B", "C")));
assertTrue(idx.colocationColumns().containsAll(List.of("A", "B", "C")));
}
use of org.apache.ignite.schema.definition.PrimaryKeyDefinition 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);
}
Aggregations