use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testKeyValueSerialization.
@Test
public void testKeyValueSerialization() throws Exception {
Random rnd = new Random();
Tuple key1 = Tuple.create().set("keyUuidCol", UUID.randomUUID());
Tuple val1 = 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("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));
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
Row row = new Row(fullSchema, new ByteBufferRow(marshaller.marshal(key1, val1).bytes()));
Tuple key2 = deserializeTuple(serializeTuple(TableRow.keyTuple(row)));
Tuple val2 = deserializeTuple(serializeTuple(TableRow.valueTuple(row)));
assertEquals(key1, key2);
assertEquals(val1, val2);
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testKeyValueTupleSchemaAwareness.
@Test
public void testKeyValueTupleSchemaAwareness() 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);
key.set("foo", "bar");
assertNotNull(((SchemaAware) tuple).schema());
assertNull(((SchemaAware) key).schema());
assertNotNull(((SchemaAware) val).schema());
val.set("id", 1L);
assertNotNull(((SchemaAware) tuple).schema());
assertNull(((SchemaAware) key).schema());
assertNull(((SchemaAware) val).schema());
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testTupleEquality.
@Test
public void testTupleEquality() throws Exception {
Random rnd = new Random();
Tuple keyTuple = Tuple.create().set("keyUuidCol", UUID.randomUUID());
Tuple valTuple = 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("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 tuple = Tuple.create(valTuple).set(keyTuple.columnName(0), keyTuple.value(0));
// Check tuples backed with Row.
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
Row row = new Row(fullSchema, new ByteBufferRow(marshaller.marshal(keyTuple, valTuple).bytes()));
Tuple rowKeyTuple = TableRow.keyTuple(row);
Tuple rowValTuple = TableRow.valueTuple(row);
final Tuple rowTuple = TableRow.tuple(new Row(fullSchema, new ByteBufferRow(marshaller.marshal(tuple).bytes())));
assertEquals(keyTuple, rowKeyTuple);
assertEquals(rowKeyTuple, keyTuple);
assertEquals(valTuple, rowValTuple);
assertEquals(rowValTuple, valTuple);
assertEquals(tuple, rowTuple);
assertEquals(rowTuple, tuple);
// Check deserialized.
Tuple keyTuple2 = deserializeTuple(serializeTuple(rowKeyTuple));
Tuple valTuple2 = deserializeTuple(serializeTuple(rowValTuple));
final Tuple tuple2 = deserializeTuple(serializeTuple(rowTuple));
assertEquals(keyTuple, keyTuple2);
assertEquals(keyTuple2, keyTuple);
assertEquals(valTuple, valTuple2);
assertEquals(valTuple2, valTuple);
assertEquals(tuple, tuple2);
assertEquals(tuple2, tuple);
// Check the tuples backed with Row after update.
rowKeyTuple.set("foo", "bar");
rowValTuple.set("foo", "bar");
rowTuple.set("foo", "bar");
assertNotEquals(keyTuple, rowKeyTuple);
assertNotEquals(rowKeyTuple, keyTuple);
assertNotEquals(valTuple, rowValTuple);
assertNotEquals(rowValTuple, valTuple);
assertNotEquals(tuple, rowTuple);
assertNotEquals(rowTuple, tuple);
// Update original to make them equal.
keyTuple.set("foo", "bar");
valTuple.set("foo", "bar");
tuple.set("foo", "bar");
assertEquals(keyTuple, rowKeyTuple);
assertEquals(rowKeyTuple, keyTuple);
assertEquals(valTuple, rowValTuple);
assertEquals(rowValTuple, valTuple);
assertEquals(tuple, rowTuple);
assertEquals(rowTuple, tuple);
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testKeyValueChunks.
@Test
public void testKeyValueChunks() throws TupleMarshallerException {
SchemaDescriptor schema = new SchemaDescriptor(42, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("name".toUpperCase(), NativeTypes.STRING, true), new Column("price".toUpperCase(), NativeTypes.DOUBLE, true) });
Tuple original = Tuple.create().set("id", 3L).set("name", "Shirt").set("price", 5.99d);
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
Row row = new Row(schema, new ByteBufferRow(marshaller.marshal(original).bytes()));
Tuple key = TableRow.keyTuple(row);
Tuple val = TableRow.valueTuple(row);
assertEquals(3L, (Long) key.value("id"));
assertEquals(3L, (Long) key.value(0));
assertEquals("Shirt", val.value("name"));
assertEquals("Shirt", val.value(1));
assertEquals(5.99d, val.value("price"));
assertEquals(5.99d, val.value(0));
// Wrong columns.
assertThrows(IndexOutOfBoundsException.class, () -> key.value(1));
assertThrows(IllegalArgumentException.class, () -> key.value("price"));
assertThrows(IndexOutOfBoundsException.class, () -> val.value(2));
assertThrows(IllegalArgumentException.class, () -> val.value("id"));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testRowTupleMutability.
@Test
public void testRowTupleMutability() 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);
tuple.set("id", 2L);
assertEquals(2L, (Long) tuple.value("id"));
assertEquals(1L, (Long) key.value("id"));
tuple.set("name", "noname");
assertEquals("noname", tuple.value("name"));
assertEquals("Shirt", val.value("name"));
tuple.set("foo", "bar");
assertEquals("bar", tuple.value("foo"));
assertThrows(IllegalArgumentException.class, () -> key.value("foo"));
assertThrows(IllegalArgumentException.class, () -> val.value("foo"));
}
Aggregations