Search in sources :

Example 1 with TupleMarshallerImpl

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

the class TupleMarshallerVarlenOnlyBenchmark method init.

/**
 * Setup.
 */
@Setup
public void init() {
    final long seed = System.currentTimeMillis();
    final boolean useString = "string".equals(type);
    rnd = new Random(seed);
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", INT64, false, (Supplier<Object> & Serializable) () -> 0L) }, IntStream.range(0, fieldsCount).boxed().map(i -> new Column("col" + i, useString ? STRING : BYTES, 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();
        }
    });
    if (useString) {
        final byte[] data = new byte[dataSize / fieldsCount];
        for (int i = 0; i < data.length; i++) {
            data[i] = (byte) (rnd.nextInt() & 0x7F);
        }
        // Latin1 string.
        val = new String(data, StandardCharsets.ISO_8859_1);
    } else {
        rnd.nextBytes((byte[]) (val = new byte[dataSize / fieldsCount]));
    }
}
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) Supplier(java.util.function.Supplier) Warmup(org.openjdk.jmh.annotations.Warmup) INT64(org.apache.ignite.internal.schema.NativeTypes.INT64) 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) StandardCharsets(java.nio.charset.StandardCharsets) Benchmark(org.openjdk.jmh.annotations.Benchmark) Serializable(java.io.Serializable) TimeUnit(java.util.concurrent.TimeUnit) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder) BYTES(org.apache.ignite.internal.schema.NativeTypes.BYTES) STRING(org.apache.ignite.internal.schema.NativeTypes.STRING) 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) Serializable(java.io.Serializable) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Random(java.util.Random) Column(org.apache.ignite.internal.schema.Column) Supplier(java.util.function.Supplier) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with TupleMarshallerImpl

use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl 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);
}
Also used : Random(java.util.Random) 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 3 with TupleMarshallerImpl

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

use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl 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);
}
Also used : Random(java.util.Random) 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) Test(org.junit.jupiter.api.Test)

Example 5 with TupleMarshallerImpl

use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl 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);
}
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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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