Search in sources :

Example 16 with TupleMarshaller

use of org.apache.ignite.internal.schema.marshaller.TupleMarshaller 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));
}
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) Tuple(org.apache.ignite.table.Tuple) BigDecimal(java.math.BigDecimal) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with TupleMarshaller

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

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