Search in sources :

Example 21 with BinaryRow

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

the class KeyValueViewImpl method replaceAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Boolean> replaceAsync(@Nullable Transaction tx, @NotNull K key, V oldVal, V newVal) {
    Objects.requireNonNull(key);
    BinaryRow oldRow = marshal(key, oldVal);
    BinaryRow newRow = marshal(key, newVal);
    return tbl.replace(oldRow, newRow, (InternalTransaction) tx);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with BinaryRow

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

the class KeyValueViewImpl method marshal.

/**
 * Marshal keys to a row.
 *
 * @param keys Key objects.
 * @return Binary rows.
 */
@NotNull
public Collection<BinaryRow> marshal(@NotNull Collection<K> keys) {
    final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> keyRows = new ArrayList<>(keys.size());
    try {
        for (K key : keys) {
            final BinaryRow keyRow = marsh.marshal(Objects.requireNonNull(key));
            keyRows.add(keyRow);
        }
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
    return keyRows;
}
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) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with BinaryRow

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

the class KeyValueViewImpl method unmarshalPairs.

/**
 * Marshal key-value pairs.
 *
 * @param rows Binary rows.
 * @return Key-value pairs.
 */
@NotNull
public Map<K, V> unmarshalPairs(Collection<BinaryRow> rows) {
    if (rows.isEmpty()) {
        return Collections.emptyMap();
    }
    final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
    Map<K, V> pairs = new HashMap<>(rows.size());
    try {
        for (Row row : schemaReg.resolve(rows)) {
            if (row != null) {
                pairs.put(marsh.unmarshalKey(row), marsh.unmarshalValue(row));
            }
        }
        return pairs;
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) HashMap(java.util.HashMap) IgniteException(org.apache.ignite.lang.IgniteException) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with BinaryRow

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

the class ModifyNode method flushTuples.

private void flushTuples(boolean force) {
    if (nullOrEmpty(rows) || !force && rows.size() < MODIFY_BATCH_SIZE) {
        return;
    }
    List<ModifyRow> rows = this.rows;
    this.rows = new ArrayList<>(MODIFY_BATCH_SIZE);
    Map<ModifyRow.Operation, Collection<BinaryRow>> operations = getOperationsPerAction(rows);
    // TODO: IGNITE-15087 Implement support for transactional SQL
    for (Map.Entry<ModifyRow.Operation, Collection<BinaryRow>> op : operations.entrySet()) {
        switch(op.getKey()) {
            case INSERT_ROW:
                Collection<BinaryRow> conflictKeys = tableView.insertAll(op.getValue(), null).join();
                if (!conflictKeys.isEmpty()) {
                    IgniteTypeFactory typeFactory = context().getTypeFactory();
                    RowHandler.RowFactory<RowT> rowFactory = context().rowHandler().factory(context().getTypeFactory(), table.descriptor().insertRowType(typeFactory));
                    List<String> conflictKeys0 = conflictKeys.stream().map(binRow -> table.toRow(context(), binRow, rowFactory, null)).map(context().rowHandler()::toString).collect(Collectors.toList());
                    throw conflictKeysException(conflictKeys0);
                }
                break;
            case UPDATE_ROW:
                tableView.upsertAll(op.getValue(), null).join();
                break;
            case DELETE_ROW:
                tableView.deleteAll(op.getValue(), null).join();
                break;
            default:
                throw new UnsupportedOperationException(op.getKey().name());
        }
    }
    updatedRows += rows.size();
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) ModifyRow(org.apache.ignite.internal.sql.engine.schema.ModifyRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) RowHandler(org.apache.ignite.internal.sql.engine.exec.RowHandler) Collection(java.util.Collection) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 25 with BinaryRow

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

Aggregations

BinaryRow (org.apache.ignite.internal.schema.BinaryRow)57 Row (org.apache.ignite.internal.schema.row.Row)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 MethodSource (org.junit.jupiter.params.provider.MethodSource)19 Column (org.apache.ignite.internal.schema.Column)18 ArrayList (java.util.ArrayList)13 NotNull (org.jetbrains.annotations.NotNull)11 IgniteException (org.apache.ignite.lang.IgniteException)10 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 Subscription (java.util.concurrent.Flow.Subscription)6 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)4 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 Flow (java.util.concurrent.Flow)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3