Search in sources :

Example 16 with Tuple

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

the class AbstractBasicIntegrationTest method insertData.

protected static void insertData(Table table, String[] columnNames, Object[]... tuples) {
    RecordView<Tuple> view = table.recordView();
    int batchSize = 128;
    List<Tuple> batch = new ArrayList<>(batchSize);
    for (Object[] tuple : tuples) {
        assert tuple != null && tuple.length == columnNames.length;
        Tuple toInsert = Tuple.create();
        for (int i = 0; i < tuple.length; i++) {
            toInsert.set(columnNames[i], tuple[i]);
        }
        batch.add(toInsert);
        if (batch.size() == batchSize) {
            Collection<Tuple> duplicates = view.insertAll(null, batch);
            if (!duplicates.isEmpty()) {
                throw new AssertionError("Duplicated rows detected: " + duplicates);
            }
            batch.clear();
        }
    }
    if (!batch.isEmpty()) {
        view.insertAll(null, batch);
        batch.clear();
    }
}
Also used : ArrayList(java.util.ArrayList) Tuple(org.apache.ignite.table.Tuple)

Example 17 with Tuple

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

the class RecordBinaryViewOperationsTest method getAndUpsert.

@Test
public void getAndUpsert() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    final Tuple tuple = Tuple.create().set("id", 1L).set("val", 11L);
    final Tuple newTuple = Tuple.create().set("id", 1L).set("val", 22L);
    assertNull(tbl.get(null, Tuple.create().set("id", 1L)));
    // Insert new tuple.
    assertNull(tbl.getAndUpsert(null, tuple));
    assertEqualsRows(schema, tuple, tbl.get(null, Tuple.create().set("id", 1L)));
    // Update exited row.
    assertEqualsRows(schema, tuple, tbl.getAndUpsert(null, newTuple));
    assertEqualsRows(schema, newTuple, tbl.get(null, Tuple.create().set("id", 1L)));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 18 with Tuple

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

the class RecordBinaryViewOperationsTest method replaceExact.

@Test
public void replaceExact() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    final Tuple tuple = Tuple.create().set("id", 1L).set("val", 11L);
    final Tuple tuple2 = Tuple.create().set("id", 1L).set("val", 22L);
    assertNull(tbl.get(null, Tuple.create().set("id", 1L)));
    // Ignore replace operation for non-existed row.
    // TODO: IGNITE-14479: Fix default value usage.
    // assertTrue(tbl.replace(keyTuple, tuple));
    // assertNull(tbl.get(keyTuple));
    // assertNull(tbl.get(tbl.tupleBuilder().set("id", 1L).set("val", -1)));
    // Insert row.
    tbl.insert(null, tuple);
    // Replace existed row.
    assertTrue(tbl.replace(null, tuple, tuple2));
    assertEqualsRows(schema, tuple2, tbl.get(null, Tuple.create().set("id", 1L)));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 19 with Tuple

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

the class RecordBinaryViewOperationsTest method getAll.

@Test
public void getAll() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    Tuple rec1 = Tuple.create().set("id", 1L).set("val", 11L);
    Tuple rec3 = Tuple.create().set("id", 3L).set("val", 33L);
    tbl.upsertAll(null, List.of(rec1, rec3));
    Collection<Tuple> res = tbl.getAll(null, List.of(Tuple.create().set("id", 1L), Tuple.create().set("id", 2L), Tuple.create().set("id", 3L)));
    assertEquals(2, res.size());
    assertTrue(res.contains(rec1));
    assertTrue(res.contains(rec1));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 20 with Tuple

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

the class SchemaValidationTest method stringTypeMatch.

@Test
public void stringTypeMatch() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id", NativeTypes.INT64, false) }, new Column[] { new Column("valString", NativeTypes.stringOf(3), true) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    Tuple tuple = Tuple.create().set("id", 1L);
    tbl.insert(null, tuple.set("valString", "qwe"));
    tbl.insert(null, tuple.set("valString", "qw"));
    tbl.insert(null, tuple.set("valString", "q"));
    tbl.insert(null, tuple.set("valString", ""));
    tbl.insert(null, tuple.set("valString", null));
    // Check string 3 char length and 9 bytes.
    tbl.insert(null, tuple.set("valString", "我是谁"));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Aggregations

Tuple (org.apache.ignite.table.Tuple)130 Test (org.junit.jupiter.api.Test)101 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)33 Table (org.apache.ignite.table.Table)27 Column (org.apache.ignite.internal.schema.Column)25 Row (org.apache.ignite.internal.schema.row.Row)21 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)19 Ignite (org.apache.ignite.Ignite)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)17 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)17 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)17 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)10 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)9 ArrayList (java.util.ArrayList)8 Disabled (org.junit.jupiter.api.Disabled)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)7 BigDecimal (java.math.BigDecimal)6 Transaction (org.apache.ignite.tx.Transaction)6