Search in sources :

Example 16 with TupleMarshallerImpl

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"));
}
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)

Example 17 with TupleMarshallerImpl

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));
}
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) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with TupleMarshallerImpl

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));
}
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 19 with TupleMarshallerImpl

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));
}
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)19 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)19 Tuple (org.apache.ignite.table.Tuple)19 Row (org.apache.ignite.internal.schema.row.Row)17 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)17 Test (org.junit.jupiter.api.Test)13 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)10 Column (org.apache.ignite.internal.schema.Column)10 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Random (java.util.Random)6 BigDecimal (java.math.BigDecimal)3 SchemaAware (org.apache.ignite.internal.schema.SchemaAware)3 TupleMarshallerException (org.apache.ignite.internal.schema.marshaller.TupleMarshallerException)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 TimeUnit (java.util.concurrent.TimeUnit)2 IntStream (java.util.stream.IntStream)2 Columns (org.apache.ignite.internal.schema.Columns)2 SchemaRegistryImpl (org.apache.ignite.internal.schema.registry.SchemaRegistryImpl)2 INITIAL_SCHEMA_VERSION (org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION)2