Search in sources :

Example 41 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class RecordViewImpl method unmarshal.

/**
 * Unmarshal value object from given binary row.
 *
 * @param binaryRow Binary row.
 * @return Value object.
 */
private R unmarshal(BinaryRow binaryRow) {
    if (binaryRow == null || !binaryRow.hasValue()) {
        return null;
    }
    Row row = schemaReg.resolve(binaryRow);
    RecordMarshaller<R> marshaller = marshaller(row.schemaVersion());
    try {
        return marshaller.unmarshal(row);
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row)

Example 42 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class TupleMarshallerFixlenOnlyBenchmark method measureTupleBuildAndMarshallerCost.

/**
 * Measure tuple build then marshall.
 *
 * @param bh Black hole.
 */
@Benchmark
public void measureTupleBuildAndMarshallerCost(Blackhole bh) throws TupleMarshallerException {
    final Columns cols = schema.valueColumns();
    final Tuple valBld = Tuple.create(cols.length());
    for (int i = 0; i < cols.length(); i++) {
        valBld.set(cols.column(i).name(), vals[i]);
    }
    Tuple keyTuple = Tuple.create(1).set("key", rnd.nextLong());
    final Row row = marshaller.marshal(keyTuple, valBld);
    bh.consume(row);
}
Also used : Columns(org.apache.ignite.internal.schema.Columns) Row(org.apache.ignite.internal.schema.row.Row) Tuple(org.apache.ignite.table.Tuple) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 43 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class TupleMarshallerVarlenOnlyBenchmark method measureTupleBuildAndMarshallerCost.

/**
 * Measure tuple build then marshall.
 *
 * @param bh Black hole.
 */
@Benchmark
public void measureTupleBuildAndMarshallerCost(Blackhole bh) throws TupleMarshallerException {
    final Columns cols = schema.valueColumns();
    final Tuple valBld = Tuple.create(cols.length());
    for (int i = 0; i < cols.length(); i++) {
        valBld.set(cols.column(i).name(), val);
    }
    Tuple keyTuple = Tuple.create(1).set("key", rnd.nextLong());
    final Row row = marshaller.marshal(keyTuple, valBld);
    bh.consume(row);
}
Also used : Columns(org.apache.ignite.internal.schema.Columns) Row(org.apache.ignite.internal.schema.row.Row) Tuple(org.apache.ignite.table.Tuple) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 44 with Row

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

Example 45 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class MutableRowTupleAdapterTest method testKeyValueSerialization.

@Test
public void testKeyValueSerialization() throws Exception {
    Random rnd = new Random();
    Tuple key1 = Tuple.create().set("keyUuidCol", UUID.randomUUID());
    Tuple val1 = 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("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(key1, val1).bytes()));
    Tuple key2 = deserializeTuple(serializeTuple(TableRow.keyTuple(row)));
    Tuple val2 = deserializeTuple(serializeTuple(TableRow.valueTuple(row)));
    assertEquals(key1, key2);
    assertEquals(val1, val2);
}
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)

Aggregations

Row (org.apache.ignite.internal.schema.row.Row)83 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)55 Column (org.apache.ignite.internal.schema.Column)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)30 NotNull (org.jetbrains.annotations.NotNull)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 Tuple (org.apache.ignite.table.Tuple)21 Test (org.junit.jupiter.api.Test)18 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)15 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)15 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)15 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)14 ArrayList (java.util.ArrayList)8 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)6 Random (java.util.Random)5 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)5 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)5 IgniteException (org.apache.ignite.lang.IgniteException)5