Search in sources :

Example 6 with TupleMarshaller

use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller in project ignite-3 by apache.

the class NumericTypesSerializerTest method testSameBinaryRepresentation.

/**
 * Test.
 */
@ParameterizedTest
@MethodSource("sameDecimals")
public void testSameBinaryRepresentation(Pair<BigInteger, BigInteger> pair) throws Exception {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(19, 3), false) });
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    long randomKey = rnd.nextLong();
    final Tuple firstTup = createTuple().set("key", randomKey).set("decimalCol", pair.getFirst());
    final Tuple secondTup = createTuple().set("key", randomKey).set("decimalCol", pair.getSecond());
    final Row firstRow = marshaller.marshal(firstTup);
    final Row secondRow = marshaller.marshal(secondTup);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    firstRow.writeTo(stream);
    byte[] firstRowInBytes = stream.toByteArray();
    stream.reset();
    secondRow.writeTo(stream);
    byte[] secondRowInBytes = stream.toByteArray();
    assertArrayEquals(firstRowInBytes, secondRowInBytes);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with TupleMarshaller

use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller in project ignite-3 by apache.

the class NumericTypesSerializerTest method testPrecisionRestrictionsForDecimal.

@Test
public void testPrecisionRestrictionsForDecimal() {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(9, 3), false) });
    final Tuple badTup = createTuple().set("key", rnd.nextLong());
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("123456789.0123"))), "Failed to set decimal value for column");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("-1234567890123"))), "Failed to set decimal value for column");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("1234567"))), "Failed to set decimal value for column");
    assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("12345678.9"))), "Failed to set decimal value for column");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with TupleMarshaller

use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller 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 9 with TupleMarshaller

use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller 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 10 with TupleMarshaller

use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller 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

TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)17 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)17 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)17 Tuple (org.apache.ignite.table.Tuple)17 Row (org.apache.ignite.internal.schema.row.Row)15 Test (org.junit.jupiter.api.Test)13 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)10 Column (org.apache.ignite.internal.schema.Column)8 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Random (java.util.Random)4 BigDecimal (java.math.BigDecimal)3 SchemaAware (org.apache.ignite.internal.schema.SchemaAware)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BigInteger (java.math.BigInteger)1 TupleMarshallerException (org.apache.ignite.internal.schema.marshaller.TupleMarshallerException)1