use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testVariousColumnTypes.
@Test
public void testVariousColumnTypes() throws TupleMarshallerException {
Random rnd = new Random();
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
Tuple tuple = 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("keyUuidCol", UUID.randomUUID()).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 rowTuple = TableRow.tuple(new Row(fullSchema, new ByteBufferRow(marshaller.marshal(tuple).bytes())));
assertEquals(tuple, rowTuple);
// Force row to tuple conversion.
rowTuple.set("foo", "bar");
// Force row to tuple conversion.
tuple.set("foo", "bar");
assertEquals(tuple, rowTuple);
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testRowTupleSchemaAwareness.
@Test
public void testRowTupleSchemaAwareness() 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);
assertNotNull(((SchemaAware) tuple).schema());
assertNotNull(((SchemaAware) key).schema());
assertNotNull(((SchemaAware) val).schema());
tuple.set("name", "noname");
assertNull(((SchemaAware) tuple).schema());
assertNotNull(((SchemaAware) key).schema());
assertNotNull(((SchemaAware) val).schema());
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testSerialization.
@Test
public void testSerialization() throws Exception {
Random rnd = new Random();
Tuple tup1 = 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("keyUuidCol", UUID.randomUUID()).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(tup1).bytes()));
Tuple tup2 = deserializeTuple(serializeTuple(TableRow.tuple(row)));
assertEquals(tup1, tup2);
assertEquals(tup2, tup1);
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller in project ignite-3 by apache.
the class NumericTypesSerializerTest method testStringDecimalSpecialCase.
@Test
public void testStringDecimalSpecialCase() throws TupleMarshallerException {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(1, 0), false) });
// representation of "0000" value.
final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", new BigDecimal("0E+3"));
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Row row = marshaller.marshal(tup);
assertEquals(row.decimalValue(1), BigDecimal.ZERO);
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller in project ignite-3 by apache.
the class NumericTypesSerializerTest method testPrecisionRestrictionsForNumbers.
@Test
public void testPrecisionRestrictionsForNumbers() {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("number1", NativeTypes.numberOf(5), false) });
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Tuple badTup = createTuple().set("key", rnd.nextLong());
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", BigInteger.valueOf(999991L))), "Column's type mismatch");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", new BigInteger("111111"))), "Column's type mismatch");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", BigInteger.valueOf(-999991L))), "Column's type mismatch");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", new BigInteger("-111111"))), "Column's type mismatch");
}
Aggregations