use of org.apache.ignite.internal.schema.ByteBufferRow 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.internal.schema.ByteBufferRow 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.internal.schema.ByteBufferRow 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"));
}
use of org.apache.ignite.internal.schema.ByteBufferRow in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testKeyValueTupleMutability.
@Test
public void testKeyValueTupleMutability() 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("id", 3L);
assertEquals(3L, (Long) key.value("id"));
assertEquals(1L, (Long) tuple.value("id"));
val.set("name", "noname");
assertEquals("noname", val.value("name"));
assertEquals("Shirt", tuple.value("name"));
val.set("foo", "bar");
assertEquals("bar", val.value("foo"));
assertThrows(IllegalArgumentException.class, () -> key.value("foo"));
assertThrows(IllegalArgumentException.class, () -> tuple.value("foo"));
}
use of org.apache.ignite.internal.schema.ByteBufferRow in project ignite-3 by apache.
the class ItTablePersistenceTest method createKeyValueRow.
/**
* Creates a {@link Row} with the supplied key and value.
*
* @param id Key.
* @param value Value.
* @return Row.
*/
private static Row createKeyValueRow(long id, long value) {
RowAssembler rowBuilder = new RowAssembler(SCHEMA, 0, 0);
rowBuilder.appendLong(id);
rowBuilder.appendLong(value);
return new Row(SCHEMA, new ByteBufferRow(rowBuilder.toBytes()));
}
Aggregations