Search in sources :

Example 6 with EvalProjection

use of io.crate.execution.dsl.projection.EvalProjection in project crate by crate.

the class Eval method addEvalProjection.

private ExecutionPlan addEvalProjection(PlannerContext plannerContext, ExecutionPlan executionPlan, Row params, SubQueryResults subQueryResults) {
    PositionalOrderBy orderBy = executionPlan.resultDescription().orderBy();
    PositionalOrderBy newOrderBy = null;
    SubQueryAndParamBinder binder = new SubQueryAndParamBinder(params, subQueryResults);
    List<Symbol> boundOutputs = Lists2.map(outputs, binder);
    if (orderBy != null) {
        newOrderBy = orderBy.tryMapToNewOutputs(source.outputs(), boundOutputs);
        if (newOrderBy == null) {
            executionPlan = Merge.ensureOnHandler(executionPlan, plannerContext);
        }
    }
    InputColumns.SourceSymbols ctx = new InputColumns.SourceSymbols(Lists2.map(source.outputs(), binder));
    executionPlan.addProjection(new EvalProjection(InputColumns.create(boundOutputs, ctx)), executionPlan.resultDescription().limit(), executionPlan.resultDescription().offset(), newOrderBy);
    return executionPlan;
}
Also used : PositionalOrderBy(io.crate.planner.PositionalOrderBy) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) Symbol(io.crate.expression.symbol.Symbol)

Example 7 with EvalProjection

use of io.crate.execution.dsl.projection.EvalProjection in project crate by crate.

the class HashJoin method createEvalProjectionForDistributionJoinSymbol.

private List<Symbol> createEvalProjectionForDistributionJoinSymbol(Symbol firstJoinSymbol, List<Symbol> outputs, ExecutionPlan executionPlan) {
    List<Symbol> projectionOutputs = new ArrayList<>(outputs.size() + 1);
    projectionOutputs.addAll(outputs);
    projectionOutputs.add(firstJoinSymbol);
    EvalProjection evalProjection = new EvalProjection(InputColumns.create(projectionOutputs, new InputColumns.SourceSymbols(outputs)));
    executionPlan.addProjection(evalProjection);
    return projectionOutputs;
}
Also used : EvalProjection(io.crate.execution.dsl.projection.EvalProjection) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList)

Example 8 with EvalProjection

use of io.crate.execution.dsl.projection.EvalProjection in project crate by crate.

the class GroupByPlannerTest method testGroupByHaving.

@Test
public void testGroupByHaving() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge distributedGroupByMerge = e.plan("select avg(date), name from users group by name having min(date) > '1970-01-01'");
    Merge reduceMerge = (Merge) distributedGroupByMerge.subPlan();
    CollectPhase collectPhase = ((Collect) reduceMerge.subPlan()).collectPhase();
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    MergePhase reducePhase = reduceMerge.mergePhase();
    assertThat(reducePhase.projections().size(), is(3));
    // grouping
    assertThat(reducePhase.projections().get(0), instanceOf(GroupProjection.class));
    GroupProjection groupProjection = (GroupProjection) reducePhase.projections().get(0);
    assertThat(groupProjection.values().size(), is(2));
    // filter the having clause
    assertThat(reducePhase.projections().get(1), instanceOf(FilterProjection.class));
    FilterProjection filterProjection = (FilterProjection) reducePhase.projections().get(1);
    assertThat(reducePhase.projections().get(2), instanceOf(EvalProjection.class));
    EvalProjection eval = (EvalProjection) reducePhase.projections().get(2);
    assertThat(eval.outputs().get(0).valueType(), Is.<DataType>is(DataTypes.DOUBLE));
    assertThat(eval.outputs().get(1).valueType(), Is.<DataType>is(DataTypes.STRING));
}
Also used : FilterProjection(io.crate.execution.dsl.projection.FilterProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

EvalProjection (io.crate.execution.dsl.projection.EvalProjection)8 Symbol (io.crate.expression.symbol.Symbol)4 Collect (io.crate.planner.node.dql.Collect)4 MergePhase (io.crate.execution.dsl.phases.MergePhase)3 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)3 InputColumn (io.crate.expression.symbol.InputColumn)3 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)2 ColumnIndexWriterProjection (io.crate.execution.dsl.projection.ColumnIndexWriterProjection)2 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)2 InputColumns (io.crate.execution.dsl.projection.builder.InputColumns)2 SelectSymbol (io.crate.expression.symbol.SelectSymbol)2 Reference (io.crate.metadata.Reference)2 Merge (io.crate.planner.Merge)2 OrderBy (io.crate.analyze.OrderBy)1 AbstractTableRelation (io.crate.analyze.relations.AbstractTableRelation)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 DocKeys (io.crate.analyze.where.DocKeys)1