Search in sources :

Example 1 with EqOperator

use of io.crate.expression.operator.EqOperator 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 EqOperator

use of io.crate.expression.operator.EqOperator 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 EqOperator

use of io.crate.expression.operator.EqOperator in project crate by crate.

the class DocLevelCollectTest method testCollectDocLevelWhereClause.

@Test
public void testCollectDocLevelWhereClause() throws Throwable {
    List<Symbol> arguments = Arrays.asList(testDocLevelReference, Literal.of(2));
    EqOperator op = (EqOperator) functions.get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
    List<Symbol> toCollect = Collections.singletonList(testDocLevelReference);
    WhereClause whereClause = new WhereClause(new Function(op.signature(), arguments, EqOperator.RETURN_TYPE));
    RoutedCollectPhase collectNode = getCollectNode(toCollect, whereClause);
    Bucket result = collect(collectNode);
    assertThat(result, contains(isRow(2)));
}
Also used : Function(io.crate.expression.symbol.Function) EqOperator(io.crate.expression.operator.EqOperator) Bucket(io.crate.data.Bucket) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) Symbol(io.crate.expression.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Aggregations

EqOperator (io.crate.expression.operator.EqOperator)3 Function (io.crate.expression.symbol.Function)3 Symbol (io.crate.expression.symbol.Symbol)3 Test (org.junit.Test)3 Bucket (io.crate.data.Bucket)2 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)2 InputColumn (io.crate.expression.symbol.InputColumn)2 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 TestingRowConsumer (io.crate.testing.TestingRowConsumer)2 WhereClause (io.crate.analyze.WhereClause)1 CollectionBucket (io.crate.data.CollectionBucket)1 Projector (io.crate.data.Projector)1 Row (io.crate.data.Row)1 RowConsumer (io.crate.data.RowConsumer)1 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)1 GroupingProjector (io.crate.execution.engine.aggregation.GroupingProjector)1 StreamBucket (io.crate.execution.engine.distribution.StreamBucket)1 SortingProjector (io.crate.execution.engine.sort.SortingProjector)1 SortingTopNProjector (io.crate.execution.engine.sort.SortingTopNProjector)1 TestingHelpers.isRow (io.crate.testing.TestingHelpers.isRow)1