use of org.apache.ignite.schema.definition.builder.TableDefinitionBuilder in project ignite-3 by apache.
the class SchemaDescriptorConverterTest method testComplexPrimaryKey.
/**
* Convert table with complex primary key and check it.
*/
@Test
public void testComplexPrimaryKey() {
TableDefinitionBuilder bldr = getBuilder(false, false);
TableDefinition tblSchm = bldr.withPrimaryKey(SchemaBuilders.primaryKey().withColumns("INT8", "ID").build()).build();
SchemaDescriptor tblDscr = SchemaDescriptorConverter.convert(1, tblSchm);
assertEquals(2, tblDscr.keyColumns().length());
assertEquals(2, tblDscr.colocationColumns().length);
assertEquals(columns - 2, tblDscr.valueColumns().length());
}
use of org.apache.ignite.schema.definition.builder.TableDefinitionBuilder in project ignite-3 by apache.
the class SchemaDescriptorConverterTest method testComplexPrimaryKeyWithAffinity.
/**
* Convert table with complex primary key with affinity column configured and check it.
*/
@Test
public void testComplexPrimaryKeyWithAffinity() {
TableDefinitionBuilder bldr = getBuilder(false, false);
TableDefinition tblSchm = bldr.withPrimaryKey(SchemaBuilders.primaryKey().withColumns("INT8", "ID").withColocationColumns("INT8").build()).build();
SchemaDescriptor tblDscr = SchemaDescriptorConverter.convert(1, tblSchm);
assertEquals(2, tblDscr.keyColumns().length());
assertEquals(1, tblDscr.colocationColumns().length);
assertEquals(columns - 2, tblDscr.valueColumns().length());
}
use of org.apache.ignite.schema.definition.builder.TableDefinitionBuilder in project ignite-3 by apache.
the class SchemaConfigurationTest method testInitialSchema.
/**
* TestInitialSchema.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@Test
public void testInitialSchema() {
final TableDefinitionBuilder builder = SchemaBuilders.tableBuilder(SchemaObject.DEFAULT_DATABASE_SCHEMA_NAME, "table1");
builder.columns(// Declaring columns in user order.
SchemaBuilders.column("id", ColumnType.INT64).build(), SchemaBuilders.column("label", ColumnType.stringOf(2)).withDefaultValueExpression("AI").build(), SchemaBuilders.column("name", ColumnType.string()).build(), SchemaBuilders.column("data", ColumnType.blobOf(255)).asNullable(true).build(), SchemaBuilders.column("affId", ColumnType.INT32).build()).withPrimaryKey(// Declare index column in order.
SchemaBuilders.primaryKey().withColumns("id", "affId", "name").withColocationColumns(// Optional colocation declaration. If not set, all PK columns will be colocation cols.
"affId").build()).withIndex(SchemaBuilders.sortedIndex("idx_1_sorted").addIndexColumn("id").desc().done().addIndexColumn("name").asc().done().withHints(// In-line key-hash as well.
Map.of("INLINE_SIZE", "42", "INLINE_STRATEGY", "INLINE_HASH")).build()).withIndex(SchemaBuilders.partialIndex("idx_2_partial").addIndexColumn("id").desc().done().addIndexColumn("name").asc().done().withExpression("id > 0").withHints(Map.of("INLINE_COLUMNS", "id")).build()).withIndex(SchemaBuilders.hashIndex("idx_3_hash").withColumns("id", "affId").build()).build();
}
use of org.apache.ignite.schema.definition.builder.TableDefinitionBuilder in project ignite-3 by apache.
the class TableDefinitionBuilderTest method testBuild.
/**
* Create table schema and check its parameters.
*/
@Test
public void testBuild() {
TableDefinitionBuilder builder = SchemaBuilders.tableBuilder("SNAME", "TNAME").columns(SchemaBuilders.column("COL1", ColumnType.DOUBLE).build(), SchemaBuilders.column("COL2", ColumnType.DOUBLE).build()).withPrimaryKey("COL1");
TableDefinition tbl = builder.build();
assertEquals("SNAME.TNAME", tbl.canonicalName());
assertEquals("TNAME", tbl.name());
assertEquals(1, tbl.keyColumns().size());
}
use of org.apache.ignite.schema.definition.builder.TableDefinitionBuilder in project ignite-3 by apache.
the class SchemaDescriptorConverterTest method getBuilder.
/**
* Get TableSchemaBuilder with default table.
*
* @param nullable If all columns should be nullable.
* @param withPk If builder should contains primary key index.
* @return TableSchemaBuilder.
*/
private TableDefinitionBuilder getBuilder(boolean nullable, boolean withPk) {
Function<ColumnDefinitionBuilder, ColumnDefinition> postProcess = builder -> builder.asNullable(nullable).build();
TableDefinitionBuilder res = SchemaBuilders.tableBuilder("SCHEMA", "TABLE").columns(SchemaBuilders.column("ID", ColumnType.UUID).build(), postProcess.apply(SchemaBuilders.column("INT8", ColumnType.INT8)), postProcess.apply(SchemaBuilders.column("INT16", ColumnType.INT16)), postProcess.apply(SchemaBuilders.column("INT32", ColumnType.INT32)), postProcess.apply(SchemaBuilders.column("INT64", ColumnType.INT64)), postProcess.apply(SchemaBuilders.column("FLOAT", ColumnType.FLOAT)), postProcess.apply(SchemaBuilders.column("DOUBLE", ColumnType.DOUBLE)), postProcess.apply(SchemaBuilders.column("UUID", ColumnType.UUID)), postProcess.apply(SchemaBuilders.column("STRING", ColumnType.string())), postProcess.apply(SchemaBuilders.column("STRING_FS10", ColumnType.stringOf(10))), postProcess.apply(SchemaBuilders.column("BLOB", ColumnType.blobOf())), postProcess.apply(SchemaBuilders.column("BLOB_FS10", ColumnType.blobOf(10))), postProcess.apply(SchemaBuilders.column("DECIMAL", ColumnType.decimalOf(1, 1))), postProcess.apply(SchemaBuilders.column("NUMBER", ColumnType.numberOf(12))), postProcess.apply(SchemaBuilders.column("BITMASK_FS10", ColumnType.bitmaskOf(10))));
if (withPk) {
res.withPrimaryKey("ID");
}
return res;
}
Aggregations