Search in sources :

Example 31 with Row

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

the class RecordBinaryViewImpl method replaceAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Boolean> replaceAsync(@Nullable Transaction tx, @NotNull Tuple rec) {
    Objects.requireNonNull(rec);
    final Row row = marshal(rec, false);
    return tbl.replace(row, (InternalTransaction) tx);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with Row

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

the class KeyValueBinaryViewImpl method putIfAbsentAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Boolean> putIfAbsentAsync(@Nullable Transaction tx, @NotNull Tuple key, Tuple val) {
    Objects.requireNonNull(key);
    // Convert to portable format to pass TX/storage layer.
    Row row = marshal(key, val);
    return tbl.insert(row, (InternalTransaction) tx);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with Row

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

the class SerializerBenchmarkTest method measureSerializeDeserializeCost.

/**
 * Measure serialization-deserialization operation cost.
 *
 * @param bh Black hole.
 * @throws Exception If failed.
 */
@Benchmark
public void measureSerializeDeserializeCost(Blackhole bh) throws Exception {
    Long key = rnd.nextLong();
    Object val = objectFactory.create();
    BinaryRow row = marshaller.marshal(key, val);
    Object restoredKey = marshaller.unmarshalKey(new Row(schema, row));
    Object restoredVal = marshaller.unmarshalValue(new Row(schema, row));
    bh.consume(restoredVal);
    bh.consume(restoredKey);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 34 with Row

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

the class RecordViewImpl method unmarshal.

/**
 * Unmarshal records.
 *
 * @param rows Row collection.
 * @return Records collection.
 */
@NotNull
public Collection<R> unmarshal(Collection<BinaryRow> rows) {
    if (rows.isEmpty()) {
        return Collections.emptyList();
    }
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<R> recs = new ArrayList<>(rows.size());
    try {
        for (Row row : schemaReg.resolve(rows)) {
            if (row != null) {
                recs.add(marsh.unmarshal(row));
            }
        }
        return recs;
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with Row

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

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