use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method remove.
@Test
public void remove() {
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);
// Put KV pair.
tbl.put(null, key, val);
// Delete existed key.
assertEqualsValues(schema, val, tbl.get(null, key));
assertTrue(tbl.remove(null, key));
assertNull(tbl.get(null, key));
// Delete already deleted key.
assertFalse(tbl.remove(null, key));
// Put KV pair.
tbl.put(null, key, val2);
assertEqualsValues(schema, val2, tbl.get(null, key));
// Delete existed key.
assertTrue(tbl.remove(null, Tuple.create().set("id", 1L)));
assertNull(tbl.get(null, key));
// Delete not existed key.
assertNull(tbl.get(null, key2));
assertFalse(tbl.remove(null, key2));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method put.
@Test
public void put() {
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));
// Put KV pair.
tbl.put(null, key, val);
assertEqualsValues(schema, val, tbl.get(null, key));
assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
// Update KV pair.
tbl.put(null, key, val2);
assertEqualsValues(schema, val2, tbl.get(null, key));
assertEqualsValues(schema, val2, tbl.get(null, Tuple.create().set("id", 1L)));
// Remove KV pair.
tbl.put(null, key, null);
assertNull(tbl.get(null, key));
// Put KV pair.
tbl.put(null, key, val3);
assertEqualsValues(schema, val3, tbl.get(null, key));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method replace.
@Test
public void replace() {
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);
final Tuple val3 = Tuple.create().set("val", 33L);
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key, val));
assertNull(tbl.get(null, key));
tbl.put(null, key, val);
// Replace existed KV pair.
assertTrue(tbl.replace(null, key, val2));
assertEqualsValues(schema, val2, tbl.get(null, key));
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key2, val3));
assertNull(tbl.get(null, key2));
tbl.put(null, key, val3);
assertEqualsValues(schema, val3, tbl.get(null, key));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testVariousColumnTypes.
@Test
public void testVariousColumnTypes() throws TupleMarshallerException {
Random rnd = new Random();
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
Tuple tuple = Tuple.create().set("valByteCol", (byte) 1).set("valShortCol", (short) 2).set("valIntCol", 3).set("valLongCol", 4L).set("valFloatCol", 0.055f).set("valDoubleCol", 0.066d).set("keyUuidCol", UUID.randomUUID()).set("valDateCol", LocalDate.now()).set("valDateTimeCol", truncatedLocalDateTimeNow()).set("valTimeCol", truncatedLocalTimeNow()).set("valTimeStampCol", truncatedInstantNow()).set("valBitmask1Col", randomBitSet(rnd, 12)).set("valBytesCol", IgniteTestUtils.randomBytes(rnd, 13)).set("valStringCol", IgniteTestUtils.randomString(rnd, 14)).set("valNumberCol", BigInteger.valueOf(rnd.nextLong())).set("valDecimalCol", BigDecimal.valueOf(rnd.nextLong(), 5));
Tuple rowTuple = TableRow.tuple(new Row(fullSchema, new ByteBufferRow(marshaller.marshal(tuple).bytes())));
assertEquals(tuple, rowTuple);
// Force row to tuple conversion.
rowTuple.set("foo", "bar");
// Force row to tuple conversion.
tuple.set("foo", "bar");
assertEquals(tuple, rowTuple);
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testRowTupleSchemaAwareness.
@Test
public void testRowTupleSchemaAwareness() throws TupleMarshallerException {
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
Row row = new Row(schema, new ByteBufferRow(marshaller.marshal(Tuple.create().set("id", 1L).set("name", "Shirt")).bytes()));
Tuple tuple = TableRow.tuple(row);
Tuple key = TableRow.keyTuple(row);
final Tuple val = TableRow.valueTuple(row);
assertTrue(tuple instanceof SchemaAware);
assertNotNull(((SchemaAware) tuple).schema());
assertNotNull(((SchemaAware) key).schema());
assertNotNull(((SchemaAware) val).schema());
tuple.set("name", "noname");
assertNull(((SchemaAware) tuple).schema());
assertNotNull(((SchemaAware) key).schema());
assertNotNull(((SchemaAware) val).schema());
}
Aggregations