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);
}
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;
}
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);
}
}
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();
}
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);
}
Aggregations