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);
}
Aggregations