use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl 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.marshaller.TupleMarshallerImpl in project ignite-3 by apache.
the class NumericTypesSerializerTest method testDecimalMaxScale.
@Test
public void testDecimalMaxScale() throws TupleMarshallerException {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(Integer.MAX_VALUE, Integer.MAX_VALUE), false) });
final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", BigDecimal.valueOf(123, Integer.MAX_VALUE));
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Row row = marshaller.marshal(tup);
assertEquals(row.decimalValue(1), BigDecimal.valueOf(123, Integer.MAX_VALUE));
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl in project ignite-3 by apache.
the class NumericTypesSerializerTest method testUpscaleForDecimal.
/**
* Test.
*/
@ParameterizedTest
@MethodSource("stringDecimalRepresentation")
public void testUpscaleForDecimal(String decimalStr) throws TupleMarshallerException {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol1", NativeTypes.decimalOf(9, 0), false) });
final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol1", new BigDecimal(decimalStr));
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Row row = marshaller.marshal(tup);
assertEquals(row.decimalValue(1), new BigDecimal(decimalStr).setScale(0, RoundingMode.HALF_UP));
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl in project ignite-3 by apache.
the class NumericTypesSerializerTest method testNumber.
/**
* Test.
*/
@ParameterizedTest
@MethodSource("numbers")
public void testNumber(Pair<BigInteger, BigInteger> pair) throws TupleMarshallerException {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("number1", NativeTypes.numberOf(19), false), new Column("number2", NativeTypes.numberOf(10), false) });
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Tuple tup = createTuple().set("key", rnd.nextLong()).set("number1", pair.getFirst()).set("number2", pair.getSecond());
final Row row = marshaller.marshal(tup);
assertEquals(row.numberValue(1), row.numberValue(2));
}
Aggregations