Search in sources :

Example 11 with ByteBufferRow

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());
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler)

Example 12 with ByteBufferRow

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());
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler)

Example 13 with ByteBufferRow

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();
    }
}
Also used : TupleMarshallerException(org.apache.ignite.internal.schema.marshaller.TupleMarshallerException) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)

Example 14 with ByteBufferRow

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);
}
Also used : Random(java.util.Random) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test)

Example 15 with ByteBufferRow

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());
}
Also used : SchemaAware(org.apache.ignite.internal.schema.SchemaAware) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)22 Row (org.apache.ignite.internal.schema.row.Row)14 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)10 Tuple (org.apache.ignite.table.Tuple)10 Test (org.junit.jupiter.api.Test)10 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)7 Random (java.util.Random)5 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)4 Column (org.apache.ignite.internal.schema.Column)3 SchemaAware (org.apache.ignite.internal.schema.SchemaAware)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)2 Timestamp (org.apache.ignite.internal.tx.Timestamp)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1