use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method defaultValues.
@Test
public void defaultValues() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, true, () -> 28L), new Column("str".toUpperCase(), NativeTypes.stringOf(3), true, () -> "ABC"), new Column("blob".toUpperCase(), NativeTypes.blobOf(3), true, () -> new byte[] { 0, 1, 2 }) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
final Tuple keyTuple0 = Tuple.create().set("id", 0L);
final Tuple keyTuple1 = Tuple.create().set("id", 1L);
final Tuple tuple0 = Tuple.create().set("id", 0L);
final Tuple tupleExpected0 = Tuple.create().set("id", 0L).set("val", 28L).set("str", "ABC").set("blob", new byte[] { 0, 1, 2 });
final Tuple tuple1 = Tuple.create().set("id", 1L).set("val", null).set("str", null).set("blob", null);
tbl.insert(null, tuple0);
tbl.insert(null, tuple1);
assertEqualsRows(schema, tupleExpected0, tbl.get(null, keyTuple0));
assertEqualsRows(schema, tuple1, tbl.get(null, keyTuple1));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method remove.
@Test
public void remove() {
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();
tbl.upsert(null, Tuple.create().set("id", 1L).set("val", 11L));
final Tuple keyTuple = Tuple.create().set("id", 1L);
// Delete not existed keyTuple.
assertFalse(tbl.delete(null, Tuple.create().set("id", 2L)));
// Delete existed keyTuple.
assertTrue(tbl.delete(null, keyTuple));
assertNull(tbl.get(null, keyTuple));
// Delete already deleted keyTuple.
assertFalse(tbl.delete(null, keyTuple));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method validateSchema.
@Test
public void validateSchema() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, true), new Column("str".toUpperCase(), NativeTypes.stringOf(3), true), new Column("blob".toUpperCase(), NativeTypes.blobOf(3), true) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
final Tuple keyTuple0 = new TestTupleBuilder().set("id", 0).set("id1", 0);
final Tuple keyTuple1 = new TestTupleBuilder().set("id1", 0);
final Tuple tuple0 = new TestTupleBuilder().set("id", 1L).set("str", "qweqweqwe").set("val", 11L);
final Tuple tuple1 = new TestTupleBuilder().set("id", 1L).set("blob", new byte[] { 0, 1, 2, 3 }).set("val", 22L);
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.get(null, keyTuple0));
assertThrowsWithCause(SchemaMismatchException.class, () -> tbl.get(null, keyTuple1));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple0));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple1));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple0));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple1));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple0));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple1));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class ClientKeyValueBinaryViewTest method testGetAndReplace.
@Test
public void testGetAndReplace() {
KeyValueView<Tuple, Tuple> kvView = defaultTable().keyValueView();
kvView.put(null, tupleKey(1L), tupleVal("1"));
assertNull(kvView.getAndReplace(null, tupleKey(2L), tupleVal("2")));
Tuple res = kvView.getAndReplace(null, tupleKey(1L), tupleVal("2"));
assertEquals("1", res.stringValue(0));
assertEquals("2", kvView.get(null, tupleKey(1L)).stringValue(0));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class ClientKeyValueBinaryViewTest method testKvPutRecordGet.
@Test
public void testKvPutRecordGet() {
Table table = defaultTable();
KeyValueView<Tuple, Tuple> kvView = table.keyValueView();
Tuple key = defaultTupleKey();
Tuple val = Tuple.create().set("name", "bar");
kvView.put(null, key, val);
Tuple res = table.recordView().get(null, key);
assertEquals("bar", res.stringValue("name"));
assertEquals(DEFAULT_ID, res.longValue("id"));
}
Aggregations