Search in sources :

Example 6 with TupleMarshallerImpl

use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl 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");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) BigInteger(java.math.BigInteger) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with TupleMarshallerImpl

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

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

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

the class TupleMarshallerFixlenOnlyBenchmark method init.

/**
 * Setup.
 */
@Setup
public void init() {
    long seed = System.currentTimeMillis();
    rnd = new Random(seed);
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, IntStream.range(0, fieldsCount).boxed().map(i -> new Column("col" + i, NativeTypes.INT64, nullable)).toArray(Column[]::new));
    marshaller = new TupleMarshallerImpl(new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION) {

        @Override
        public SchemaDescriptor schema() {
            return schema;
        }

        @Override
        public SchemaDescriptor schema(int ver) {
            return schema;
        }

        @Override
        public int lastSchemaVersion() {
            return schema.version();
        }
    });
    vals = new Object[schema.valueColumns().length()];
    for (int i = 0; i < vals.length; i++) {
        vals[i] = rnd.nextLong();
    }
}
Also used : IntStream(java.util.stream.IntStream) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Measurement(org.openjdk.jmh.annotations.Measurement) Blackhole(org.openjdk.jmh.infra.Blackhole) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Random(java.util.Random) Scope(org.openjdk.jmh.annotations.Scope) Warmup(org.openjdk.jmh.annotations.Warmup) Row(org.apache.ignite.internal.schema.row.Row) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) INITIAL_SCHEMA_VERSION(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION) Runner(org.openjdk.jmh.runner.Runner) RunnerException(org.openjdk.jmh.runner.RunnerException) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Setup(org.openjdk.jmh.annotations.Setup) Columns(org.apache.ignite.internal.schema.Columns) Mode(org.openjdk.jmh.annotations.Mode) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerException(org.apache.ignite.internal.schema.marshaller.TupleMarshallerException) Param(org.openjdk.jmh.annotations.Param) State(org.openjdk.jmh.annotations.State) Benchmark(org.openjdk.jmh.annotations.Benchmark) TimeUnit(java.util.concurrent.TimeUnit) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) Column(org.apache.ignite.internal.schema.Column) Fork(org.openjdk.jmh.annotations.Fork) Tuple(org.apache.ignite.table.Tuple) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Random(java.util.Random) Column(org.apache.ignite.internal.schema.Column) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Setup(org.openjdk.jmh.annotations.Setup)

Example 10 with TupleMarshallerImpl

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

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