use of io.crate.data.UnsafeArrayRow in project crate by crate.
the class FetchRows method updatedOutputRow.
public Row updatedOutputRow(Object[] incomingCells, IntFunction<ReaderBucket> getReaderBucket) {
for (int i = 0; i < fetchIdPositions.length; i++) {
int fetchIdPos = fetchIdPositions[i];
Long fetchId = (Long) incomingCells[fetchIdPos];
UnsafeArrayRow fetchedRow = fetchedRows.get(fetchIdPos);
if (fetchId == null) {
fetchedRow.cells(nullRows.get(i));
} else {
int readerId = FetchId.decodeReaderId(fetchId);
int docId = FetchId.decodeDocId(fetchId);
fetchedRow.cells(getReaderBucket.apply(readerId).get(docId));
}
}
inputRow.cells(incomingCells);
return output;
}
use of io.crate.data.UnsafeArrayRow in project crate by crate.
the class FetchRows method create.
public static FetchRows create(TransactionContext txnCtx, NodeContext nodeCtx, Map<RelationName, FetchSource> fetchSourceByTable, List<Symbol> outputSymbols) {
IntArrayList fetchIdPositions = new IntArrayList();
ArrayList<Object[]> nullRows = new ArrayList<>();
IntObjectHashMap<UnsafeArrayRow> fetchedRows = new IntObjectHashMap<>();
for (var fetchSource : fetchSourceByTable.values()) {
Object[] nullRow = new Object[fetchSource.references().size()];
for (InputColumn ic : fetchSource.fetchIdCols()) {
fetchIdPositions.add(ic.index());
nullRows.add(nullRow);
fetchedRows.put(ic.index(), new UnsafeArrayRow());
}
}
final UnsafeArrayRow inputRow = new UnsafeArrayRow();
var visitor = new BaseImplementationSymbolVisitor<Void>(txnCtx, nodeCtx) {
@Override
public Input<?> visitInputColumn(final InputColumn inputColumn, final Void context) {
final int idx = inputColumn.index();
return () -> inputRow.get(idx);
}
@Override
public Input<?> visitFetchReference(final FetchReference fetchReference, final Void context) {
var ref = fetchReference.ref();
UnsafeArrayRow row = fetchedRows.get(fetchReference.fetchId().index());
int posInFetchedRow = fetchSourceByTable.get(ref.ident().tableIdent()).references().indexOf(ref);
return () -> row.get(posInFetchedRow);
}
};
List<Input<?>> outputExpressions = Lists2.map(outputSymbols, x -> x.accept(visitor, null));
return new FetchRows(fetchIdPositions, outputExpressions, inputRow, fetchedRows, nullRows);
}
Aggregations