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();
}
}
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)));
}
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)));
}
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));
}
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", "我是谁"));
}
Aggregations