Search in sources :

Example 1 with TableDefinitionBuilder

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());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with TableDefinitionBuilder

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());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with TableDefinitionBuilder

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();
}
Also used : TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with TableDefinitionBuilder

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());
}
Also used : TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Test(org.junit.jupiter.api.Test)

Example 5 with TableDefinitionBuilder

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;
}
Also used : Arrays(java.util.Arrays) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Columns(org.apache.ignite.internal.schema.Columns) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition) ColumnType(org.apache.ignite.schema.definition.ColumnType) Function(java.util.function.Function) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) ColumnDefinitionBuilder(org.apache.ignite.schema.definition.builder.ColumnDefinitionBuilder) Test(org.junit.jupiter.api.Test) TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) Column(org.apache.ignite.internal.schema.Column) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ColumnDefinitionBuilder(org.apache.ignite.schema.definition.builder.ColumnDefinitionBuilder) TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition)

Aggregations

TableDefinitionBuilder (org.apache.ignite.schema.definition.builder.TableDefinitionBuilder)6 Test (org.junit.jupiter.api.Test)6 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)4 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 Arrays (java.util.Arrays)1 Function (java.util.function.Function)1 Column (org.apache.ignite.internal.schema.Column)1 Columns (org.apache.ignite.internal.schema.Columns)1 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)1 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)1 ColumnDefinition (org.apache.ignite.schema.definition.ColumnDefinition)1 ColumnType (org.apache.ignite.schema.definition.ColumnType)1 ColumnDefinitionBuilder (org.apache.ignite.schema.definition.builder.ColumnDefinitionBuilder)1 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1