Search in sources :

Example 31 with BinaryRow

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

the class RecordViewImpl method marshalKeys.

/**
 * Marshal key-records.
 *
 * @param recs Records collection.
 * @return Binary rows collection.
 */
private Collection<BinaryRow> marshalKeys(@NotNull Collection<R> recs) {
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> rows = new ArrayList<>(recs.size());
    try {
        for (R rec : recs) {
            final BinaryRow row = marsh.marshalKey(Objects.requireNonNull(rec));
            rows.add(row);
        }
        return rows;
    } 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)

Example 32 with BinaryRow

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

the class RecordViewImpl method replaceAsync.

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

Example 33 with BinaryRow

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

the class RecordViewImpl method marshal.

/**
 * Marshal records.
 *
 * @param recs Records collection.
 * @return Binary rows collection.
 */
private Collection<BinaryRow> marshal(@NotNull Collection<R> recs) {
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> rows = new ArrayList<>(recs.size());
    try {
        for (R rec : recs) {
            final BinaryRow row = marsh.marshal(Objects.requireNonNull(rec));
            rows.add(row);
        }
        return rows;
    } 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)

Example 34 with BinaryRow

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

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

the class PartitionListener method handleScanRetrieveBatchCommand.

/**
 * Handler for the {@link ScanRetrieveBatchCommand}.
 *
 * @param clo Command closure.
 * @param cmd Command.
 */
private void handleScanRetrieveBatchCommand(CommandClosure<ScanRetrieveBatchCommand> clo, ScanRetrieveBatchCommand cmd) {
    CursorMeta cursorDesc = cursors.get(cmd.scanId());
    if (cursorDesc == null) {
        clo.result(new NoSuchElementException(format("Cursor with id={} is not found on server side.", cmd.scanId())));
        return;
    }
    AtomicInteger internalBatchCounter = cursorDesc.batchCounter();
    if (internalBatchCounter.getAndSet(clo.command().batchCounter()) != clo.command().batchCounter() - 1) {
        throw new IllegalStateException("Counters from received scan command and handled scan command in partition listener are inconsistent");
    }
    List<BinaryRow> res = new ArrayList<>();
    try {
        for (int i = 0; i < cmd.itemsToRetrieveCount() && cursorDesc.cursor().hasNext(); i++) {
            res.add(cursorDesc.cursor().next());
        }
    } catch (NoSuchElementException e) {
        clo.result(e);
    }
    clo.result(new MultiRowsResponse(res));
}
Also used : MultiRowsResponse(org.apache.ignite.internal.table.distributed.command.response.MultiRowsResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) NoSuchElementException(java.util.NoSuchElementException)

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