Search in sources :

Example 1 with EqOperator

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

the class ProjectionToProjectorVisitorTest method testFilterProjection.

@Test
public void testFilterProjection() throws Exception {
    EqOperator op = (EqOperator) functions.get(new FunctionIdent(EqOperator.NAME, ImmutableList.of(DataTypes.INTEGER, DataTypes.INTEGER)));
    Function function = new Function(op.info(), Arrays.asList(Literal.of(2), new InputColumn(1)));
    FilterProjection projection = new FilterProjection(function, Arrays.asList(new InputColumn(0), new InputColumn(1)));
    Projector projector = visitor.create(projection, RAM_ACCOUNTING_CONTEXT, UUID.randomUUID());
    assertThat(projector, instanceOf(FilterProjector.class));
    List<Object[]> rows = new ArrayList<>();
    rows.add($("human", 2));
    rows.add($("vogon", 1));
    BatchIterator filteredBI = projector.apply(RowsBatchIterator.newInstance(new CollectionBucket(rows), 2));
    TestingBatchConsumer consumer = new TestingBatchConsumer();
    consumer.accept(filteredBI, null);
    Bucket bucket = consumer.getBucket();
    assertThat(bucket.size(), is(1));
}
Also used : EqOperator(io.crate.operation.operator.EqOperator) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with EqOperator

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

the class DocLevelCollectTest method testCollectDocLevelWhereClause.

@Test
public void testCollectDocLevelWhereClause() throws Throwable {
    EqOperator op = (EqOperator) functions.get(new FunctionIdent(EqOperator.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER, DataTypes.INTEGER)));
    List<Symbol> toCollect = Collections.<Symbol>singletonList(testDocLevelReference);
    WhereClause whereClause = new WhereClause(new Function(op.info(), Arrays.<Symbol>asList(testDocLevelReference, Literal.of(2))));
    RoutedCollectPhase collectNode = getCollectNode(toCollect, whereClause);
    Bucket result = collect(collectNode);
    assertThat(result, contains(isRow(2)));
}
Also used : Function(io.crate.analyze.symbol.Function) EqOperator(io.crate.operation.operator.EqOperator) Bucket(io.crate.data.Bucket) Symbol(io.crate.analyze.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Aggregations

EqOperator (io.crate.operation.operator.EqOperator)2 Test (org.junit.Test)2 WhereClause (io.crate.analyze.WhereClause)1 Function (io.crate.analyze.symbol.Function)1 Symbol (io.crate.analyze.symbol.Symbol)1 Bucket (io.crate.data.Bucket)1 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)1 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)1