Search in sources :

Example 6 with TableDefinition

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

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

the class ItBaselineChangesTest method testBaselineExtending.

/**
 * Check dynamic table creation.
 */
@Test
void testBaselineExtending(TestInfo testInfo) {
    initClusterNodes.forEach((nodeName, configStr) -> clusterNodes.add(IgnitionManager.start(nodeName, configStr, workDir.resolve(nodeName))));
    assertEquals(3, clusterNodes.size());
    // Create table on node 0.
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "tbl1").columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("key").build();
    clusterNodes.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(5).changePartitions(1));
    // Put data on node 1.
    Table tbl1 = clusterNodes.get(1).tables().table(schTbl1.canonicalName());
    RecordView<Tuple> recView1 = tbl1.recordView();
    recView1.insert(null, Tuple.create().set("key", 1L).set("val", 111));
    var metaStoreNode = clusterNodes.get(0);
    var node3Name = testNodeName(testInfo, nodePort(3));
    var node4Name = testNodeName(testInfo, nodePort(4));
    // Start 2 new nodes after
    var node3 = IgnitionManager.start(node3Name, buildConfig(metaStoreNode.name(), 3), workDir.resolve(node3Name));
    clusterNodes.add(node3);
    var node4 = IgnitionManager.start(node4Name, buildConfig(metaStoreNode.name(), 4), workDir.resolve(node4Name));
    clusterNodes.add(node4);
    // Update baseline to nodes 1,4,5
    metaStoreNode.setBaseline(Set.of(metaStoreNode.name(), node3Name, node4Name));
    IgnitionManager.stop(clusterNodes.get(1).name());
    IgnitionManager.stop(clusterNodes.get(2).name());
    Table tbl4 = node4.tables().table(schTbl1.canonicalName());
    final Tuple keyTuple1 = Tuple.create().set("key", 1L);
    assertEquals(1, (Long) tbl4.recordView().get(null, keyTuple1).value("key"));
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 8 with TableDefinition

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

the class ItDynamicTableCreationTest method testDynamicTableCreation.

/**
 * Check dynamic table creation.
 */
@Test
void testDynamicTableCreation() {
    startGrid();
    // Create table on node 0.
    TableDefinition scmTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "tbl1").columns(SchemaBuilders.column("key", ColumnType.UUID).build(), SchemaBuilders.column("affKey", ColumnType.INT64).build(), SchemaBuilders.column("valStr", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("valInt", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("valNull", ColumnType.INT16).asNullable(true).build()).withPrimaryKey(SchemaBuilders.primaryKey().withColumns("key", "affKey").withColocationColumns("affKey").build()).build();
    clusterNodes.get(0).tables().createTable(scmTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(scmTbl1, tblCh).changeReplicas(1).changePartitions(10));
    final UUID uuid = UUID.randomUUID();
    final UUID uuid2 = UUID.randomUUID();
    // Put data on node 1.
    Table tbl1 = clusterNodes.get(1).tables().table(scmTbl1.canonicalName());
    RecordView<Tuple> recView1 = tbl1.recordView();
    KeyValueView<Tuple, Tuple> kvView1 = tbl1.keyValueView();
    recView1.insert(null, Tuple.create().set("key", uuid).set("affKey", 42L).set("valStr", "String value").set("valInt", 73).set("valNull", null));
    kvView1.put(null, Tuple.create().set("key", uuid2).set("affKey", 4242L), Tuple.create().set("valStr", "String value 2").set("valInt", 7373).set("valNull", null));
    // Get data on node 2.
    Table tbl2 = clusterNodes.get(2).tables().table(scmTbl1.canonicalName());
    final RecordView<Tuple> recView2 = tbl2.recordView();
    KeyValueView<Tuple, Tuple> kvView2 = tbl2.keyValueView();
    final Tuple keyTuple1 = Tuple.create().set("key", uuid).set("affKey", 42L);
    final Tuple keyTuple2 = Tuple.create().set("key", uuid2).set("affKey", 4242L);
    // KV view must NOT return key columns in value.
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple1).value("key"));
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple1).value("affKey"));
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple2).value("key"));
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple2).value("affKey"));
    // Record binary view MUST return key columns in value.
    assertEquals(uuid, recView2.get(null, keyTuple1).value("key"));
    assertEquals(42L, (Long) recView2.get(null, keyTuple1).value("affKey"));
    assertEquals(uuid2, recView2.get(null, keyTuple2).value("key"));
    assertEquals(4242L, (Long) recView2.get(null, keyTuple2).value("affKey"));
    assertEquals("String value", recView2.get(null, keyTuple1).value("valStr"));
    assertEquals(73, (Integer) recView2.get(null, keyTuple1).value("valInt"));
    assertNull(recView2.get(null, keyTuple1).value("valNull"));
    assertEquals("String value 2", recView2.get(null, keyTuple2).value("valStr"));
    assertEquals(7373, (Integer) recView2.get(null, keyTuple2).value("valInt"));
    assertNull(recView2.get(null, keyTuple2).value("valNull"));
    assertEquals("String value", kvView2.get(null, keyTuple1).value("valStr"));
    assertEquals(73, (Integer) kvView2.get(null, keyTuple1).value("valInt"));
    assertNull(kvView2.get(null, keyTuple1).value("valNull"));
    assertEquals("String value 2", kvView2.get(null, keyTuple2).value("valStr"));
    assertEquals(7373, (Integer) kvView2.get(null, keyTuple2).value("valInt"));
    assertNull(kvView2.get(null, keyTuple2).value("valNull"));
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) UUID(java.util.UUID) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 9 with TableDefinition

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

the class ItDynamicTableCreationTest method testDynamicSimpleTableCreation.

/**
 * Check dynamic table creation.
 */
@Test
void testDynamicSimpleTableCreation() {
    startGrid();
    // Create table on node 0.
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "tbl1").columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("key").build();
    clusterNodes.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(1).changePartitions(10));
    // Put data on node 1.
    Table tbl1 = clusterNodes.get(1).tables().table(schTbl1.canonicalName());
    RecordView<Tuple> recView1 = tbl1.recordView();
    KeyValueView<Tuple, Tuple> kvView1 = tbl1.keyValueView();
    recView1.insert(null, Tuple.create().set("key", 1L).set("val", 111));
    kvView1.put(null, Tuple.create().set("key", 2L), Tuple.create().set("val", 222));
    // Get data on node 2.
    Table tbl2 = clusterNodes.get(2).tables().table(schTbl1.canonicalName());
    RecordView<Tuple> recView2 = tbl2.recordView();
    KeyValueView<Tuple, Tuple> kvView2 = tbl2.keyValueView();
    final Tuple keyTuple1 = Tuple.create().set("key", 1L);
    final Tuple keyTuple2 = Tuple.create().set("key", 2L);
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple1).value("key"));
    assertThrows(IllegalArgumentException.class, () -> kvView2.get(null, keyTuple2).value("key"));
    assertEquals(1, (Long) recView2.get(null, keyTuple1).value("key"));
    assertEquals(2, (Long) recView2.get(null, keyTuple2).value("key"));
    assertEquals(111, (Integer) recView2.get(null, keyTuple1).value("val"));
    assertEquals(111, (Integer) kvView2.get(null, keyTuple1).value("val"));
    assertEquals(222, (Integer) recView2.get(null, keyTuple2).value("val"));
    assertEquals(222, (Integer) kvView2.get(null, keyTuple2).value("val"));
    assertThrows(IllegalArgumentException.class, () -> kvView1.get(null, keyTuple1).value("key"));
    assertThrows(IllegalArgumentException.class, () -> kvView1.get(null, keyTuple2).value("key"));
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 10 with TableDefinition

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

the class ItIgniteNodeRestartTest method nodeWithDataTest.

/**
 * Restarts the node which stores some data.
 */
@Test
@Disabled("https://issues.apache.org/jira/browse/IGNITE-16433")
public void nodeWithDataTest(TestInfo testInfo) {
    String nodeName = testNodeName(testInfo, 3344);
    Ignite ignite = IgnitionManager.start(nodeName, "{\n" + "  \"node\": {\n" + "    \"metastorageNodes\":[ " + nodeName + " ]\n" + "  },\n" + "  \"network\": {\n" + "    \"port\":3344,\n" + "    \"nodeFinder\": {\n" + "      \"netClusterNodes\":[ \"localhost:3344\" ] \n" + "    }\n" + "  }\n" + "}", workDir);
    TableDefinition scmTbl1 = SchemaBuilders.tableBuilder("PUBLIC", TABLE_NAME).columns(SchemaBuilders.column("id", ColumnType.INT32).build(), SchemaBuilders.column("name", ColumnType.string()).asNullable(true).build()).withPrimaryKey(SchemaBuilders.primaryKey().withColumns("id").build()).build();
    Table table = ignite.tables().createTable(scmTbl1.canonicalName(), tbl -> SchemaConfigurationConverter.convert(scmTbl1, tbl).changePartitions(10));
    for (int i = 0; i < 100; i++) {
        Tuple key = Tuple.create().set("id", i);
        Tuple val = Tuple.create().set("name", "name " + i);
        table.keyValueView().put(null, key, val);
    }
    IgnitionManager.stop(nodeName);
    ignite = IgnitionManager.start(nodeName, null, workDir);
    assertNotNull(ignite.tables().table(TABLE_NAME));
    for (int i = 0; i < 100; i++) {
        assertEquals("name " + i, table.keyValueView().get(null, Tuple.create().set("id", i)).stringValue("name"));
    }
    IgnitionManager.stop(nodeName);
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Ignite(org.apache.ignite.Ignite) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

TableDefinition (org.apache.ignite.schema.definition.TableDefinition)37 Test (org.junit.jupiter.api.Test)25 Table (org.apache.ignite.table.Table)14 List (java.util.List)11 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)11 ColumnType (org.apache.ignite.schema.definition.ColumnType)11 Disabled (org.junit.jupiter.api.Disabled)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Collection (java.util.Collection)9 TableDefinitionBuilder (org.apache.ignite.schema.definition.builder.TableDefinitionBuilder)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 Collections (java.util.Collections)8 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)8 RocksDbDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema)8 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)8 PartialIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema)8 SortedIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema)8 TablesConfiguration (org.apache.ignite.configuration.schemas.table.TablesConfiguration)8 AfterEach (org.junit.jupiter.api.AfterEach)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8