use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class InteropOperationsTest method readRecordBinary.
/**
* Read through record binary view.
*
* @param id Id to read.
* @param nulls If {@code true} - nullable fields should be filled, if {@code false} - otherwise.
* @return {@code true} if read successfully, {@code false} - otherwise.
*/
private boolean readRecordBinary(int id, boolean nulls) {
Tuple k = Tuple.create().set("id", (long) id);
Tuple res = R_BIN_VIEW.get(null, k);
if (res == null) {
return false;
}
validateTuple(id, res, nulls);
return true;
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method getAndPut.
@Test
public void getAndPut() {
SchemaDescriptor schema = schemaDescriptor();
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
final Tuple val3 = Tuple.create().set("val", 33L);
assertNull(tbl.get(null, key));
// Insert new tuple.
assertNull(tbl.getAndPut(null, key, val));
assertEqualsValues(schema, val, tbl.get(null, key));
assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
assertEqualsValues(schema, val, tbl.getAndPut(null, key, val2));
assertEqualsValues(schema, val2, tbl.getAndPut(null, key, Tuple.create().set("val", 33L)));
assertEqualsValues(schema, val3, tbl.get(null, key));
assertNull(tbl.get(null, Tuple.create().set("id", 2L)));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method removeExact.
@Test
public void removeExact() {
SchemaDescriptor schema = schemaDescriptor();
final KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple key2 = Tuple.create().set("id", 2L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
// Put KV pair.
tbl.put(null, key, val);
assertEqualsValues(schema, val, tbl.get(null, key));
// Fails to delete KV pair with unexpected value.
assertFalse(tbl.remove(null, key, val2));
assertEqualsValues(schema, val, tbl.get(null, key));
// Delete KV pair with expected value.
assertTrue(tbl.remove(null, key, val));
assertNull(tbl.get(null, key));
// Once again.
assertFalse(tbl.remove(null, key, val));
assertNull(tbl.get(null, key));
// Try to remove non-existed key.
assertThrows(Exception.class, () -> tbl.remove(null, key, null));
assertNull(tbl.get(null, key));
// Put KV pair.
tbl.put(null, key, val2);
assertEqualsValues(schema, val2, tbl.get(null, key));
// Check null value ignored.
assertThrows(Exception.class, () -> tbl.remove(null, key, null));
assertEqualsValues(schema, val2, tbl.get(null, key));
// Delete KV pair with expected value.
assertTrue(tbl.remove(null, key, val2));
assertNull(tbl.get(null, key));
assertFalse(tbl.remove(null, key2, val2));
assertNull(tbl.get(null, key2));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method getAll.
@Test
public void getAll() {
SchemaDescriptor schema = schemaDescriptor();
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
Tuple key1 = Tuple.create().set("id", 1L);
Tuple key2 = Tuple.create().set("id", 2L);
Tuple key3 = Tuple.create().set("id", 3L);
tbl.putAll(null, Map.of(key1, Tuple.create().set("val", 11L), key3, Tuple.create().set("val", 33L)));
Map<Tuple, Tuple> res = tbl.getAll(null, List.of(key1, key2, key3));
assertEquals(2, res.size());
assertEquals(Tuple.create().set("val", 11L), res.get(key1));
assertEquals(Tuple.create().set("val", 33L), res.get(key3));
assertNull(res.get(key2));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method replaceExact.
@Test
public void replaceExact() {
SchemaDescriptor schema = schemaDescriptor();
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple key2 = Tuple.create().set("id", 2L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key2, val, val2));
assertNull(tbl.get(null, key2));
tbl.put(null, key, val);
// Replace existed KV pair.
assertTrue(tbl.replace(null, key, val, val2));
assertEqualsValues(schema, val2, tbl.get(null, key));
}
Aggregations