use of io.crate.operation.InputFactory in project crate by crate.
the class RowTransformingBatchIteratorTest method createInputs.
@Before
public void createInputs() throws Exception {
InputFactory inputFactory = new InputFactory(getFunctions());
InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns();
inputs = Collections.singletonList(ctx.add(AddFunction.of(new InputColumn(0), Literal.of(2L))));
expressions = ctx.expressions();
}
use of io.crate.operation.InputFactory in project crate by crate.
the class FileReadingCollectorTest method prepare.
@Before
public void prepare() throws Exception {
Functions functions = new Functions(ImmutableMap.<FunctionIdent, FunctionImplementation>of(), ImmutableMap.<String, FunctionResolver>of());
inputFactory = new InputFactory(functions);
}
use of io.crate.operation.InputFactory in project crate by crate.
the class FileReadingIteratorTest method prepare.
@Before
public void prepare() throws Exception {
Functions functions = new Functions(ImmutableMap.<FunctionIdent, FunctionImplementation>of(), ImmutableMap.<String, FunctionResolver>of());
inputFactory = new InputFactory(functions);
tempFilePath = createTempFile();
File tmpFile = tempFilePath.toFile();
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFile), StandardCharsets.UTF_8)) {
writer.write("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}\n");
writer.write("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}\n");
}
}
use of io.crate.operation.InputFactory in project crate by crate.
the class SingleRowSource method getCollector.
@Override
public CrateCollector getCollector(CollectPhase phase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
collectPhase = collectPhase.normalize(clusterNormalizer, null);
if (collectPhase.whereClause().noMatch()) {
return RowsCollector.empty(consumer);
}
assert !collectPhase.whereClause().hasQuery() : "WhereClause should have been normalized to either MATCH_ALL or NO_MATCH";
InputFactory inputFactory = new InputFactory(functions);
InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns(collectPhase.toCollect());
return RowsCollector.single(new InputRow(ctx.topLevelInputs()), consumer);
}
use of io.crate.operation.InputFactory in project crate by crate.
the class RowsTransformer method toRowsIterable.
public static Iterable<Row> toRowsIterable(InputFactory inputFactory, ReferenceResolver<?> referenceResolver, RoutedCollectPhase collectPhase, Iterable<?> iterable) {
WhereClause whereClause = collectPhase.whereClause();
if (whereClause.noMatch()) {
return Collections.emptyList();
}
InputFactory.Context ctx = inputFactory.ctxForRefs(referenceResolver);
ctx.add(collectPhase.toCollect());
OrderBy orderBy = collectPhase.orderBy();
if (orderBy != null) {
for (Symbol symbol : orderBy.orderBySymbols()) {
ctx.add(symbol);
}
}
Input<Boolean> condition;
if (whereClause.hasQuery()) {
assert DataTypes.BOOLEAN.equals(whereClause.query().valueType()) : "whereClause.query() must be of type " + DataTypes.BOOLEAN;
//noinspection unchecked whereClause().query() is a symbol of type boolean so it must become Input<Boolean>
condition = (Input<Boolean>) ctx.add(whereClause.query());
} else {
condition = Literal.BOOLEAN_TRUE;
}
@SuppressWarnings("unchecked") Iterable<Row> rows = Iterables.filter(Iterables.transform(iterable, new ValueAndInputRow<>(ctx.topLevelInputs(), ctx.expressions())), InputCondition.asPredicate(condition));
if (orderBy == null) {
return rows;
}
return sortRows(Iterables.transform(rows, Row::materialize), collectPhase);
}
Aggregations