use of org.apache.ignite.internal.schema.BinaryRow 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);
}
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class CommandUtils method rowsToBytes.
/**
* Writes a list of rows to byte array.
*
* @param rows Collection of rows.
* @return Rows data.
*/
public static byte[] rowsToBytes(Collection<BinaryRow> rows) {
if (rows == null || rows.isEmpty()) {
return null;
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
for (BinaryRow row : rows) {
if (row == null) {
baos.write(intToBytes(0));
} else {
byte[] bytes = rowToBytes(row);
baos.write(intToBytes(bytes.length));
baos.write(bytes);
}
}
baos.flush();
return baos.toByteArray();
} catch (IOException e) {
LOG.error("Could not write rows to stream [rows=" + rows.size() + ']', e);
throw new IgniteInternalException(e);
}
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class PartitionListener method handleScanInitCommand.
/**
* Handler for the {@link ScanInitCommand}.
*
* @param clo Command closure.
* @param cmd Command.
*/
private void handleScanInitCommand(CommandClosure<ScanInitCommand> clo, ScanInitCommand cmd) {
IgniteUuid cursorId = cmd.scanId();
try {
Cursor<BinaryRow> cursor = storage.scan(key -> true);
cursors.put(cursorId, new CursorMeta(cursor, cmd.requesterNodeId(), new AtomicInteger(0)));
} catch (StorageException e) {
clo.result(e);
}
clo.result(null);
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class VersionedRowStore method scan.
/**
* Executes a scan.
*
* @param pred The predicate.
* @return The cursor.
*/
public Cursor<BinaryRow> scan(Predicate<SearchRow> pred) {
Cursor<DataRow> delegate = storage.scan(pred);
// TODO asch add tx support IGNITE-15087.
return new Cursor<BinaryRow>() {
@Nullable
private BinaryRow cur = null;
@Override
public void close() throws Exception {
delegate.close();
}
@NotNull
@Override
public Iterator<BinaryRow> iterator() {
return this;
}
@Override
public boolean hasNext() {
if (cur != null) {
return true;
}
if (delegate.hasNext()) {
DataRow row = delegate.next();
cur = versionedRow(row, null).getFirst();
// Skip tombstones.
return cur != null ? true : hasNext();
}
return false;
}
@Override
public BinaryRow next() {
BinaryRow next = cur;
cur = null;
assert next != null;
return next;
}
};
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class VersionedRowStore method unpack.
/**
* Unpacks a raw value into (cur, old, ts) triplet. TODO asch IGNITE-15934 not very efficient.
*
* @param row The row.
* @return The value.
*/
private static Value unpack(@Nullable DataRow row) {
if (row == null) {
return new Value(null, null, null);
}
ByteBuffer buf = row.value();
BinaryRow newVal = null;
BinaryRow oldVal = null;
int l1 = buf.asIntBuffer().get();
int pos = 4;
buf.position(pos);
if (l1 != 0) {
// TODO asch IGNITE-15934 get rid of copying
byte[] tmp = new byte[l1];
buf.get(tmp);
newVal = new ByteBufferRow(tmp);
pos += l1;
}
buf.position(pos);
int l2 = buf.asIntBuffer().get();
pos += 4;
buf.position(pos);
if (l2 != 0) {
// TODO asch get rid of copying
byte[] tmp = new byte[l2];
buf.get(tmp);
oldVal = new ByteBufferRow(tmp);
pos += l2;
}
buf.position(pos);
long ts = buf.getLong();
long nodeId = buf.getLong();
return new Value(newVal, oldVal, new Timestamp(ts, nodeId));
}
Aggregations