Search in sources :

Example 6 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItSchemaChangeTableViewTest method testStrictSchemaInsertRowOfNewSchema.

/**
 * Check operation failed if unknown column found.
 */
@Test
public void testStrictSchemaInsertRowOfNewSchema() {
    List<Ignite> grid = startGrid();
    createTable(grid);
    Table tbl = grid.get(0).tables().table(TABLE);
    Tuple tuple = Tuple.create().set("key", 1L).set("unknownColumn", 10);
    assertThrowsWithCause(SchemaMismatchException.class, () -> tbl.recordView().insert(null, tuple));
}
Also used : Table(org.apache.ignite.table.Table) Ignite(org.apache.ignite.Ignite) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 7 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItSecondaryIndexTest method initTestData.

/**
 * Before all.
 */
@BeforeAll
static void initTestData() {
    TableDefinition schema0 = SchemaBuilders.tableBuilder("PUBLIC", "DEVELOPER").columns(SchemaBuilders.column("ID", ColumnType.INT32).build(), SchemaBuilders.column("NAME", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("DEPID", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("CITY", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("AGE", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("ID").withIndex(SchemaBuilders.sortedIndex(DEPID_IDX).addIndexColumn("DEPID").done().build()).withIndex(SchemaBuilders.sortedIndex(NAME_CITY_IDX).addIndexColumn("DEPID").desc().done().addIndexColumn("CITY").desc().done().build()).withIndex(SchemaBuilders.sortedIndex(NAME_DEPID_CITY_IDX).addIndexColumn("NAME").done().addIndexColumn("DEPID").desc().done().addIndexColumn("CITY").desc().done().build()).build();
    Table dev0 = CLUSTER_NODES.get(0).tables().createTable(schema0.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schema0, tblCh).changeReplicas(2).changePartitions(10));
    insertData(dev0, new String[] { "ID", "NAME", "DEPID", "CITY", "AGE" }, new Object[][] { { 1, "Mozart", 3, "Vienna", 33 }, { 2, "Beethoven", 2, "Vienna", 44 }, { 3, "Bach", 1, "Leipzig", 55 }, { 4, "Strauss", 2, "Munich", 66 }, { 5, "Vagner", 4, "Leipzig", 70 }, { 6, "Chaikovsky", 5, "Votkinsk", 53 }, { 7, "Verdy", 6, "Rankola", 88 }, { 8, "Stravinsky", 7, "Spt", 89 }, { 9, "Rahmaninov", 8, "Starorussky ud", 70 }, { 10, "Shubert", 9, "Vienna", 31 }, { 11, "Glinka", 10, "Smolenskaya gb", 53 }, { 12, "Einaudi", 11, "", -1 }, { 13, "Glass", 12, "", -1 }, { 14, "Rihter", 13, "", -1 }, { 15, "Marradi", 14, "", -1 }, { 16, "Zimmer", 15, "", -1 }, { 17, "Hasaishi", 16, "", -1 }, { 18, "Arnalds", 17, "", -1 }, { 19, "Yiruma", 18, "", -1 }, { 20, "O'Halloran", 19, "", -1 }, { 21, "Cacciapaglia", 20, "", -1 }, { 22, "Prokofiev", 21, "", -1 }, { 23, "Musorgskii", 22, "", -1 } });
    TableDefinition schema1 = SchemaBuilders.tableBuilder("PUBLIC", "UNWRAP_PK").columns(SchemaBuilders.column("F1", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("F2", ColumnType.INT64).asNullable(true).build(), SchemaBuilders.column("F3", ColumnType.INT64).asNullable(true).build(), SchemaBuilders.column("F4", ColumnType.INT64).asNullable(true).build()).withPrimaryKey(SchemaBuilders.primaryKey().withColumns("F2", "F1").build()).withIndex(SchemaBuilders.sortedIndex(PK_IDX).addIndexColumn("F2").done().addIndexColumn("F1").done().build()).build();
    Table dev1 = CLUSTER_NODES.get(0).tables().createTable(schema1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schema1, tblCh).changeReplicas(2).changePartitions(10));
    insertData(dev1, new String[] { "F1", "F2", "F3", "F4" }, new Object[][] { { "Petr", 1L, 2L, 3L }, { "Ivan", 2L, 2L, 4L }, { "Ivan1", 21L, 2L, 4L }, { "Ivan2", 22L, 2L, 4L }, { "Ivan3", 23L, 2L, 4L }, { "Ivan4", 24L, 2L, 4L }, { "Ivan5", 25L, 2L, 4L } });
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 8 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItSetOpTest method testSetOpBigBatch.

@Test
@Disabled
public void testSetOpBigBatch() {
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "BIG_TABLE1").columns(SchemaBuilders.column("KEY", ColumnType.INT32).build(), SchemaBuilders.column("VAL", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("KEY").build();
    Table tbl1 = CLUSTER_NODES.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(2).changePartitions(10));
    TableDefinition schTbl2 = SchemaBuilders.tableBuilder("PUBLIC", "BIG_TABLE2").columns(SchemaBuilders.column("KEY", ColumnType.INT32).build(), SchemaBuilders.column("VAL", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("KEY").build();
    Table tbl2 = CLUSTER_NODES.get(0).tables().createTable(schTbl2.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl2, tblCh).changeReplicas(2).changePartitions(10));
    int key = 0;
    RecordView<Tuple> recordView1 = tbl1.recordView();
    RecordView<Tuple> recordView2 = tbl2.recordView();
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < ((i == 0) ? 1 : (1 << (i * 4 - 1))); j++) {
            // Cache1 keys count: 1 of "0", 8 of "1", 128 of "2", 2048 of "3", 32768 of "4".
            recordView1.insert(null, Tuple.create().set("KEY", key++).set("VAL", i));
            // Cache2 keys count: 1 of "5", 128 of "3", 32768 of "1".
            if ((i & 1) == 0) {
                recordView2.insert(null, Tuple.create().set("KEY", key++).set("VAL", 5 - i));
            }
        }
    }
    // Check 2 partitioned caches.
    List<List<?>> rows = sql("SELECT val FROM BIG_TABLE1 EXCEPT SELECT val FROM BIG_TABLE2");
    assertEquals(3, rows.size());
    assertEquals(1, countIf(rows, r -> r.get(0).equals(0)));
    assertEquals(1, countIf(rows, r -> r.get(0).equals(2)));
    assertEquals(1, countIf(rows, r -> r.get(0).equals(4)));
    rows = sql("SELECT val FROM BIG_TABLE1 EXCEPT ALL SELECT val FROM BIG_TABLE2");
    assertEquals(34817, rows.size());
    assertEquals(1, countIf(rows, r -> r.get(0).equals(0)));
    assertEquals(128, countIf(rows, r -> r.get(0).equals(2)));
    assertEquals(1920, countIf(rows, r -> r.get(0).equals(3)));
    assertEquals(32768, countIf(rows, r -> r.get(0).equals(4)));
    rows = sql("SELECT val FROM BIG_TABLE1 INTERSECT SELECT val FROM BIG_TABLE2");
    assertEquals(2, rows.size());
    assertEquals(1, countIf(rows, r -> r.get(0).equals(1)));
    assertEquals(1, countIf(rows, r -> r.get(0).equals(3)));
    rows = sql("SELECT val FROM BIG_TABLE1 INTERSECT ALL SELECT val FROM BIG_TABLE2");
    assertEquals(136, rows.size());
    assertEquals(8, countIf(rows, r -> r.get(0).equals(1)));
    assertEquals(128, countIf(rows, r -> r.get(0).equals(3)));
}
Also used : RecordView(org.apache.ignite.table.RecordView) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) SchemaConfigurationConverter(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter) Predicate(java.util.function.Predicate) ColumnType(org.apache.ignite.schema.definition.ColumnType) Disabled(org.junit.jupiter.api.Disabled) Test(org.junit.jupiter.api.Test) List(java.util.List) BeforeAll(org.junit.jupiter.api.BeforeAll) StreamSupport(java.util.stream.StreamSupport) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) List(java.util.List) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 9 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItSortAggregateTest method initTestData.

/**
 * Before all.
 */
@BeforeAll
static void initTestData() {
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "TEST").columns(SchemaBuilders.column("ID", ColumnType.INT32).build(), SchemaBuilders.column("GRP0", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("GRP1", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("VAL0", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("VAL1", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("ID").withIndex(SchemaBuilders.sortedIndex("IDX").addIndexColumn("GRP0").done().addIndexColumn("GRP1").done().build()).build();
    TableDefinition schTbl2 = SchemaBuilders.tableBuilder("PUBLIC", "TEST_ONE_COL_IDX").columns(SchemaBuilders.column("PK", ColumnType.INT32).build(), SchemaBuilders.column("COL0", ColumnType.INT32).asNullable(true).build()).withPrimaryKey("PK").withIndex(SchemaBuilders.sortedIndex("IDX").addIndexColumn("COL0").desc().done().build()).build();
    Table table = CLUSTER_NODES.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(2).changePartitions(10));
    Table tblOneColIdx = CLUSTER_NODES.get(0).tables().createTable(schTbl2.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl2, tblCh));
    RecordView<Tuple> view = table.recordView();
    for (int i = 0; i < ROWS; i++) {
        view.insert(null, Tuple.create().set("ID", i).set("GRP0", i / 10).set("GRP1", i / 100).set("VAL0", 1).set("VAL1", 2));
    }
    RecordView<Tuple> view1 = tblOneColIdx.recordView();
    for (int i = 0; i < ROWS; i++) {
        view1.insert(null, Tuple.create().set("PK", i).set("COL0", i));
    }
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Tuple(org.apache.ignite.table.Tuple) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ItIndexSpoolTest method prepareDataSet.

private void prepareDataSet(int rowsCount) {
    Object[][] dataRows = new Object[rowsCount][];
    for (int i = 0; i < rowsCount; i++) {
        dataRows[i] = new Object[] { i, i + 1, "val_" + i };
    }
    for (String name : List.of("TEST0", "TEST1")) {
        Table tbl = createTable(name);
        insertData(tbl, new String[] { "ID", "JID", "VAL" }, dataRows);
    }
}
Also used : Table(org.apache.ignite.table.Table)

Aggregations

Table (org.apache.ignite.table.Table)65 Test (org.junit.jupiter.api.Test)51 Tuple (org.apache.ignite.table.Tuple)29 Ignite (org.apache.ignite.Ignite)15 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)15 List (java.util.List)12 UUID (java.util.UUID)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)12 ArrayList (java.util.ArrayList)11 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)11 TableImpl (org.apache.ignite.internal.table.TableImpl)10 Function (java.util.function.Function)9 Collectors (java.util.stream.Collectors)9 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)9 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)8 ColumnType (org.apache.ignite.schema.definition.ColumnType)8 NotNull (org.jetbrains.annotations.NotNull)8 Consumer (java.util.function.Consumer)7 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)7