use of org.apache.ignite.schema.definition.builder.PrimaryKeyDefinitionBuilder 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.builder.PrimaryKeyDefinitionBuilder 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.builder.PrimaryKeyDefinitionBuilder in project ignite-3 by apache.
the class PrimaryKeyDefinitionDefinitionBuilderTest method testPrimaryKeyWrongColocationColumn.
/**
* Test primary key parameters.
*/
@Test
public void testPrimaryKeyWrongColocationColumn() {
PrimaryKeyDefinitionBuilder builder = SchemaBuilders.primaryKey().withColumns("A", "B").withColocationColumns("C");
assertThrows(IllegalStateException.class, builder::build);
}
use of org.apache.ignite.schema.definition.builder.PrimaryKeyDefinitionBuilder in project ignite-3 by apache.
the class DdlCommandHandler method handleCreateTable.
/**
* Handles create table command.
*/
private void handleCreateTable(CreateTableCommand cmd) {
final PrimaryKeyDefinitionBuilder pkeyDef = SchemaBuilders.primaryKey();
pkeyDef.withColumns(IgniteObjectName.quoteNames(cmd.primaryKeyColumns()));
pkeyDef.withColocationColumns(IgniteObjectName.quoteNames(cmd.affColumns()));
final IgniteTypeFactory typeFactory = Commons.typeFactory();
final List<org.apache.ignite.schema.definition.ColumnDefinition> colsInner = new ArrayList<>();
for (ColumnDefinition col : cmd.columns()) {
ColumnDefinitionBuilder col0 = SchemaBuilders.column(IgniteObjectName.quote(col.name()), typeFactory.columnType(col.type())).asNullable(col.nullable()).withDefaultValueExpression(col.defaultValue());
colsInner.add(col0.build());
}
Consumer<TableChange> tblChanger = tblCh -> {
TableChange conv = convert(SchemaBuilders.tableBuilder(IgniteObjectName.quote(cmd.schemaName()), IgniteObjectName.quote(cmd.tableName())).columns(colsInner).withPrimaryKey(pkeyDef.build()).build(), tblCh);
if (cmd.partitions() != null) {
conv.changePartitions(cmd.partitions());
}
if (cmd.replicas() != null) {
conv.changeReplicas(cmd.replicas());
}
};
String fullName = TableDefinitionImpl.canonicalName(IgniteObjectName.quote(cmd.schemaName()), IgniteObjectName.quote(cmd.tableName()));
try {
tableManager.createTable(fullName, tblChanger);
} catch (TableAlreadyExistsException ex) {
if (!cmd.ifTableExists()) {
throw ex;
}
}
}
Aggregations