Search in sources :

Example 1 with InputFactory

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();
}
Also used : InputFactory(io.crate.operation.InputFactory) InputColumn(io.crate.analyze.symbol.InputColumn) CollectExpression(io.crate.operation.collect.CollectExpression) Before(org.junit.Before)

Example 2 with InputFactory

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);
}
Also used : InputFactory(io.crate.operation.InputFactory) Before(org.junit.Before)

Example 3 with InputFactory

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");
    }
}
Also used : InputFactory(io.crate.operation.InputFactory) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Before(org.junit.Before)

Example 4 with InputFactory

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);
}
Also used : InputFactory(io.crate.operation.InputFactory) InputRow(io.crate.operation.InputRow) CollectExpression(io.crate.operation.collect.CollectExpression) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 5 with InputFactory

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);
}
Also used : OrderBy(io.crate.analyze.OrderBy) InputFactory(io.crate.operation.InputFactory) Symbol(io.crate.analyze.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) Row(io.crate.data.Row)

Aggregations

InputFactory (io.crate.operation.InputFactory)10 Symbol (io.crate.analyze.symbol.Symbol)5 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 Before (org.junit.Before)4 Test (org.junit.Test)4 BatchIterator (io.crate.data.BatchIterator)3 OrderBy (io.crate.analyze.OrderBy)2 CollectExpression (io.crate.operation.collect.CollectExpression)2 WhereClause (io.crate.analyze.WhereClause)1 InputColumn (io.crate.analyze.symbol.InputColumn)1 Row (io.crate.data.Row)1 NodeStatsRequest (io.crate.executor.transport.NodeStatsRequest)1 InputRow (io.crate.operation.InputRow)1 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)1 BatchIteratorTester (io.crate.testing.BatchIteratorTester)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 BytesRef (org.apache.lucene.util.BytesRef)1 ActionListener (org.elasticsearch.action.ActionListener)1