Search in sources :

Example 1 with UnsafeArrayRow

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;
}
Also used : UnsafeArrayRow(io.crate.data.UnsafeArrayRow)

Example 2 with UnsafeArrayRow

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);
}
Also used : IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList) BaseImplementationSymbolVisitor(io.crate.expression.BaseImplementationSymbolVisitor) Input(io.crate.data.Input) UnsafeArrayRow(io.crate.data.UnsafeArrayRow) InputColumn(io.crate.expression.symbol.InputColumn) FetchReference(io.crate.expression.symbol.FetchReference) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Aggregations

UnsafeArrayRow (io.crate.data.UnsafeArrayRow)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1 Input (io.crate.data.Input)1 BaseImplementationSymbolVisitor (io.crate.expression.BaseImplementationSymbolVisitor)1 FetchReference (io.crate.expression.symbol.FetchReference)1 InputColumn (io.crate.expression.symbol.InputColumn)1 ArrayList (java.util.ArrayList)1