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