use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class KeyValueViewImpl method marshal.
/**
* Marshal key-value pairs.
*
* @param pairs Key-value map.
* @return Binary rows.
*/
@NotNull
public List<BinaryRow> marshal(@NotNull Map<K, V> pairs) {
final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
List<BinaryRow> rows = new ArrayList<>(pairs.size());
try {
for (Map.Entry<K, V> pair : pairs.entrySet()) {
final BinaryRow row = marsh.marshal(Objects.requireNonNull(pair.getKey()), pair.getValue());
rows.add(row);
}
} catch (MarshallerException e) {
throw new IgniteException(e);
}
return rows;
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class KeyValueViewImpl method unmarshalValue.
/**
* Unmarshal value object from given binary row.
*
* @param binaryRow Binary row.
* @return Value object.
*/
private V unmarshalValue(BinaryRow binaryRow) {
if (binaryRow == null || !binaryRow.hasValue()) {
return null;
}
Row row = schemaReg.resolve(binaryRow);
KvMarshaller<K, V> marshaller = marshaller(row.schemaVersion());
try {
return marshaller.unmarshalValue(row);
} catch (MarshallerException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class TxAbstractTest method testScan.
@Test
public void testScan() throws InterruptedException {
accounts.recordView().upsertAll(null, List.of(makeValue(1, 100.), makeValue(2, 200.)));
Flow.Publisher<BinaryRow> pub = ((TableImpl) accounts).internalTable().scan(0, null);
List<Tuple> rows = new ArrayList<>();
CountDownLatch l = new CountDownLatch(1);
pub.subscribe(new Flow.Subscriber<BinaryRow>() {
@Override
public void onSubscribe(Flow.Subscription subscription) {
subscription.request(3);
}
@Override
public void onNext(BinaryRow item) {
Row row = ((TableImpl) accounts).schemaView().resolve(item);
rows.add(TableRow.tuple(row));
}
@Override
public void onError(Throwable throwable) {
// No-op.
}
@Override
public void onComplete() {
l.countDown();
}
});
assertTrue(l.await(5_000, TimeUnit.MILLISECONDS));
Map<Long, Tuple> map = new HashMap<>();
for (Tuple row : rows) {
map.put(row.longValue("accountNumber"), row);
}
assertEquals(100., map.get(1L).doubleValue("balance"));
assertEquals(200., map.get(2L).doubleValue("balance"));
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class ItInternalTableScanTest method testExceptionRowScan.
/**
* Checks that exception from storage cursor creation properly propagates to subscriber.
*/
@Test
public void testExceptionRowScan() throws Exception {
// The latch that allows to await Subscriber.onError() before asserting test invariants.
CountDownLatch gotExceptionLatch = new CountDownLatch(1);
AtomicReference<Throwable> gotException = new AtomicReference<>();
when(mockStorage.scan(any())).thenThrow(new StorageException("Some storage exception"));
internalTbl.scan(0, null).subscribe(new Subscriber<>() {
@Override
public void onSubscribe(Subscription subscription) {
subscription.request(1);
}
@Override
public void onNext(BinaryRow item) {
fail("Should never get here.");
}
@Override
public void onError(Throwable throwable) {
gotException.set(throwable);
gotExceptionLatch.countDown();
}
@Override
public void onComplete() {
fail("Should never get here.");
}
});
gotExceptionLatch.await();
assertEquals(gotException.get().getCause().getClass(), StorageException.class);
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class KeyValueBinaryViewImpl method getAllAsync.
/**
* {@inheritDoc}
*/
@Override
@NotNull
public CompletableFuture<Map<Tuple, Tuple>> getAllAsync(@Nullable Transaction tx, @NotNull Collection<Tuple> keys) {
Objects.requireNonNull(keys);
List<BinaryRow> keyRows = new ArrayList<>(keys.size());
for (Tuple keyRec : keys) {
final Row keyRow = marshal(keyRec, null);
keyRows.add(keyRow);
}
return tbl.getAll(keyRows, (InternalTransaction) tx).thenApply(ts -> ts.stream().filter(Objects::nonNull).filter(BinaryRow::hasValue).map(this::wrap).collect(Collectors.toMap(TableRow::keyTuple, TableRow::valueTuple)));
}
Aggregations