use of org.apache.ignite.internal.schema.ByteBufferRow in project ignite-3 by apache.
the class KvMarshallerImpl method marshal.
/**
* {@inheritDoc}
*/
@Override
public BinaryRow marshal(@NotNull K key, V val) throws MarshallerException {
assert keyClass.isInstance(key);
assert val == null || valClass.isInstance(val);
final RowAssembler asm = createAssembler(key, val);
keyMarsh.writeObject(key, asm);
valMarsh.writeObject(val, asm);
return new ByteBufferRow(asm.toBytes());
}
use of org.apache.ignite.internal.schema.ByteBufferRow in project ignite-3 by apache.
the class RecordMarshallerImpl method marshal.
/**
* {@inheritDoc}
*/
@Override
public BinaryRow marshal(@NotNull R rec) throws MarshallerException {
assert recClass.isInstance(rec);
final RowAssembler asm = createAssembler(Objects.requireNonNull(rec), rec);
recMarsh.writeObject(rec, asm);
return new ByteBufferRow(asm.toBytes());
}
use of org.apache.ignite.internal.schema.ByteBufferRow in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method getTuple.
private Tuple getTuple() {
try {
Tuple original = Tuple.create().set("id", 3L).set("name", "Shirt");
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
return TableRow.tuple(new Row(schema, new ByteBufferRow(marshaller.marshal(original).bytes())));
} catch (TupleMarshallerException e) {
return fail();
}
}
use of org.apache.ignite.internal.schema.ByteBufferRow 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.internal.schema.ByteBufferRow 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());
}
Aggregations