Search in sources :

Example 1 with BaseImplementationSymbolVisitor

use of io.crate.expression.BaseImplementationSymbolVisitor 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

IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1 Input (io.crate.data.Input)1 UnsafeArrayRow (io.crate.data.UnsafeArrayRow)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