Search in sources :

Example 1 with FilterProjection

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

the class ProjectionToProjectorVisitorTest method testFilterProjection.

@Test
public void testFilterProjection() throws Exception {
    List<Symbol> arguments = Arrays.asList(Literal.of(2), new InputColumn(1));
    EqOperator op = (EqOperator) nodeCtx.functions().get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
    Function function = new Function(op.signature(), arguments, EqOperator.RETURN_TYPE);
    FilterProjection projection = new FilterProjection(function, Arrays.asList(new InputColumn(0), new InputColumn(1)));
    Projector projector = visitor.create(projection, txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, UUID.randomUUID());
    assertThat(projector, instanceOf(FilterProjector.class));
    List<Object[]> rows = new ArrayList<>();
    rows.add($("human", 2));
    rows.add($("vogon", 1));
    BatchIterator<Row> filteredBI = projector.apply(InMemoryBatchIterator.of(new CollectionBucket(rows), SENTINEL, true));
    TestingRowConsumer consumer = new TestingRowConsumer();
    consumer.accept(filteredBI, null);
    Bucket bucket = consumer.getBucket();
    assertThat(bucket.size(), is(1));
}
Also used : Projector(io.crate.data.Projector) SortingProjector(io.crate.execution.engine.sort.SortingProjector) SortingTopNProjector(io.crate.execution.engine.sort.SortingTopNProjector) GroupingProjector(io.crate.execution.engine.aggregation.GroupingProjector) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) Function(io.crate.expression.symbol.Function) EqOperator(io.crate.expression.operator.EqOperator) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) InputColumn(io.crate.expression.symbol.InputColumn) Row(io.crate.data.Row) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) CollectionBucket(io.crate.data.CollectionBucket) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 2 with FilterProjection

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

the class ProjectingRowConsumerTest method testConsumerRequiresScrollAndProjectorsDontSupportScrolling.

@Test
public void testConsumerRequiresScrollAndProjectorsDontSupportScrolling() {
    List<Symbol> arguments = Arrays.asList(Literal.of(2), new InputColumn(1, DataTypes.INTEGER));
    EqOperator op = (EqOperator) nodeCtx.functions().get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
    Function function = new Function(op.signature(), arguments, EqOperator.RETURN_TYPE);
    FilterProjection filterProjection = new FilterProjection(function, Arrays.asList(new InputColumn(0), new InputColumn(1)));
    RowConsumer delegateConsumerRequiresScroll = new DummyRowConsumer(true);
    RowConsumer projectingConsumer = ProjectingRowConsumer.create(delegateConsumerRequiresScroll, Collections.singletonList(filterProjection), UUID.randomUUID(), txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, projectorFactory);
    assertThat(projectingConsumer.requiresScroll(), is(true));
}
Also used : Function(io.crate.expression.symbol.Function) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) EqOperator(io.crate.expression.operator.EqOperator) Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) RowConsumer(io.crate.data.RowConsumer) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 3 with FilterProjection

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

the class GroupByPlannerTest method testGroupByWithHavingAndNoSelectListReordering.

@Test
public void testGroupByWithHavingAndNoSelectListReordering() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge planNode = e.plan("select name, count(*) from users group by name having count(*) > 1");
    Merge reducerMerge = (Merge) planNode.subPlan();
    MergePhase reduceMergePhase = reducerMerge.mergePhase();
    // group projection
    // outputs: name, count(*)
    // filter projection
    // outputs: name, count(*)
    assertThat(reduceMergePhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(FilterProjection.class)));
    Projection projection = reduceMergePhase.projections().get(1);
    assertThat(projection, instanceOf(FilterProjection.class));
    FilterProjection filterProjection = (FilterProjection) projection;
    Symbol countArgument = ((Function) filterProjection.query()).arguments().get(0);
    assertThat(countArgument, instanceOf(InputColumn.class));
    // pointing to second output from group projection
    assertThat(((InputColumn) countArgument).index(), is(1));
    // outputs: name, count(*)
    assertThat(((InputColumn) filterProjection.outputs().get(0)).index(), is(0));
    assertThat(((InputColumn) filterProjection.outputs().get(1)).index(), is(1));
    MergePhase localMerge = planNode.mergePhase();
    assertThat(localMerge.projections(), empty());
}
Also used : FilterProjection(io.crate.execution.dsl.projection.FilterProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) Projection(io.crate.execution.dsl.projection.Projection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 4 with FilterProjection

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

the class GroupByPlannerTest method testGroupByHavingAndNoSelectListReOrderingWithLimit.

@Test
public void testGroupByHavingAndNoSelectListReOrderingWithLimit() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge planNode = e.plan("select name, count(*) from users group by name having count(*) > 1 limit 100");
    Merge reducerMerge = (Merge) planNode.subPlan();
    MergePhase reducePhase = reducerMerge.mergePhase();
    // group projection
    // outputs: name, count(*)
    // filter projection
    // outputs: name, count(*)
    // topN projection
    // outputs: name, count(*)
    Projection projection = reducePhase.projections().get(1);
    assertThat(projection, instanceOf(FilterProjection.class));
    FilterProjection filterProjection = (FilterProjection) projection;
    Symbol countArgument = ((Function) filterProjection.query()).arguments().get(0);
    assertThat(countArgument, instanceOf(InputColumn.class));
    // pointing to second output from group projection
    assertThat(((InputColumn) countArgument).index(), is(1));
    // outputs: name, count(*)
    assertThat(((InputColumn) filterProjection.outputs().get(0)).index(), is(0));
    assertThat(((InputColumn) filterProjection.outputs().get(1)).index(), is(1));
    // outputs: name, count(*)
    TopNProjection topN = (TopNProjection) reducePhase.projections().get(2);
    assertThat(((InputColumn) topN.outputs().get(0)).index(), is(0));
    assertThat(((InputColumn) topN.outputs().get(1)).index(), is(1));
    MergePhase localMerge = planNode.mergePhase();
    // topN projection
    // outputs: name, count(*)
    topN = (TopNProjection) localMerge.projections().get(0);
    assertThat(((InputColumn) topN.outputs().get(0)).index(), is(0));
    assertThat(((InputColumn) topN.outputs().get(1)).index(), is(1));
}
Also used : FilterProjection(io.crate.execution.dsl.projection.FilterProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) Projection(io.crate.execution.dsl.projection.Projection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 5 with FilterProjection

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

the class Filter method build.

@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> planHints, ProjectionBuilder projectionBuilder, int limit, int offset, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
    ExecutionPlan executionPlan = source.build(plannerContext, planHints, projectionBuilder, limit, offset, order, pageSizeHint, params, subQueryResults);
    Symbol boundQuery = SubQueryAndParamBinder.convert(query, params, subQueryResults);
    FilterProjection filterProjection = ProjectionBuilder.filterProjection(source.outputs(), boundQuery);
    if (executionPlan.resultDescription().executesOnShard()) {
        filterProjection.requiredGranularity(RowGranularity.SHARD);
    }
    executionPlan.addProjection(filterProjection);
    return executionPlan;
}
Also used : FilterProjection(io.crate.execution.dsl.projection.FilterProjection) ExecutionPlan(io.crate.planner.ExecutionPlan) Symbol(io.crate.expression.symbol.Symbol)

Aggregations

FilterProjection (io.crate.execution.dsl.projection.FilterProjection)10 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)9 Test (org.junit.Test)9 InputColumn (io.crate.expression.symbol.InputColumn)8 Symbol (io.crate.expression.symbol.Symbol)7 MergePhase (io.crate.execution.dsl.phases.MergePhase)6 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)6 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)5 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)5 Merge (io.crate.planner.Merge)5 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)4 Projection (io.crate.execution.dsl.projection.Projection)4 TopNProjection (io.crate.execution.dsl.projection.TopNProjection)4 GroupingProjector (io.crate.execution.engine.aggregation.GroupingProjector)2 EqOperator (io.crate.expression.operator.EqOperator)2 Function (io.crate.expression.symbol.Function)2 TestingRowConsumer (io.crate.testing.TestingRowConsumer)2 Bucket (io.crate.data.Bucket)1 CollectionBucket (io.crate.data.CollectionBucket)1 Projector (io.crate.data.Projector)1