Search in sources :

Example 11 with ColumnDefinition

use of org.apache.ignite.schema.definition.ColumnDefinition 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)

Example 12 with ColumnDefinition

use of org.apache.ignite.schema.definition.ColumnDefinition in project ignite-3 by apache.

the class ColumnDefinitionBuilderTest method testCreateColumn.

/**
 * Check column parameters.
 */
@Test
public void testCreateColumn() {
    ColumnDefinitionBuilder builder = SchemaBuilders.column("TEST", ColumnType.DOUBLE);
    ColumnDefinition col = builder.withDefaultValueExpression("NOW()").build();
    assertEquals("TEST", col.name());
    assertEquals(ColumnType.DOUBLE, col.type());
    assertEquals("NOW()", col.defaultValue());
    assertFalse(col.nullable());
}
Also used : ColumnDefinitionBuilder(org.apache.ignite.schema.definition.builder.ColumnDefinitionBuilder) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnDefinition (org.apache.ignite.schema.definition.ColumnDefinition)12 Test (org.junit.jupiter.api.Test)5 Ignite (org.apache.ignite.Ignite)4 Column (org.apache.ignite.internal.schema.Column)4 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)4 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)4 Tuple (org.apache.ignite.table.Tuple)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)2 ColumnView (org.apache.ignite.configuration.schemas.table.ColumnView)2 IndexColumnView (org.apache.ignite.configuration.schemas.table.IndexColumnView)2 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)2 ColumnType (org.apache.ignite.schema.definition.ColumnType)2 ColumnDefinitionBuilder (org.apache.ignite.schema.definition.builder.ColumnDefinitionBuilder)2 HashIndexDefinition (org.apache.ignite.schema.definition.index.HashIndexDefinition)2 IndexColumnDefinition (org.apache.ignite.schema.definition.index.IndexColumnDefinition)2 IndexDefinition (org.apache.ignite.schema.definition.index.IndexDefinition)2 PartialIndexDefinition (org.apache.ignite.schema.definition.index.PartialIndexDefinition)2 SortedIndexColumnDefinition (org.apache.ignite.schema.definition.index.SortedIndexColumnDefinition)2 SortedIndexDefinition (org.apache.ignite.schema.definition.index.SortedIndexDefinition)2