Search in sources :

Example 16 with InputColumn

use of io.crate.analyze.symbol.InputColumn in project crate by crate.

the class OrderedTopNProjectionTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    Projection p = new OrderedTopNProjection(10, 20, Collections.singletonList(Literal.of("foobar")), Collections.singletonList(new InputColumn(0, DataTypes.STRING)), new boolean[] { true }, new Boolean[] { null });
    BytesStreamOutput out = new BytesStreamOutput();
    Projection.toStream(p, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    Projection projection = Projection.fromStream(in);
    assertThat(projection, equalTo(p));
}
Also used : InputColumn(io.crate.analyze.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 17 with InputColumn

use of io.crate.analyze.symbol.InputColumn in project crate by crate.

the class OrderByPositionVisitorTest method testSymbols.

@Test
public void testSymbols() throws Exception {
    Reference ref = TestingHelpers.createReference("column", DataTypes.STRING);
    int[] orderByPositions = OrderByPositionVisitor.orderByPositions(ImmutableList.of(ref, new InputColumn(1), new InputColumn(0)), ImmutableList.of(ref, Literal.of(1)));
    assertArrayEquals(new int[] { 0, 1, 0 }, orderByPositions);
}
Also used : Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 18 with InputColumn

use of io.crate.analyze.symbol.InputColumn in project crate by crate.

the class OrderByPositionVisitorTest method testSymbolNotContained.

@Test
public void testSymbolNotContained() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Cannot sort by: other - not part of source symbols");
    Reference ref = TestingHelpers.createReference("column", DataTypes.STRING);
    OrderByPositionVisitor.orderByPositions(ImmutableList.of(ref, new InputColumn(1), TestingHelpers.createReference("other", DataTypes.LONG)), ImmutableList.of(ref, Literal.BOOLEAN_FALSE));
}
Also used : Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 19 with InputColumn

use of io.crate.analyze.symbol.InputColumn in project crate by crate.

the class InsertPlannerTest method testGroupByHavingInsertInto.

@Test
public void testGroupByHavingInsertInto() throws Exception {
    Merge planNode = e.plan("insert into users (id, name) (select name, count(*) from users group by name having count(*) > 3)");
    DistributedGroupBy groupByNode = (DistributedGroupBy) planNode.subPlan();
    MergePhase mergePhase = groupByNode.reducerMergeNode();
    assertThat(mergePhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(FilterProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    FilterProjection filterProjection = (FilterProjection) mergePhase.projections().get(1);
    assertThat(filterProjection.outputs().size(), is(2));
    assertThat(filterProjection.outputs().get(0), instanceOf(InputColumn.class));
    assertThat(filterProjection.outputs().get(1), instanceOf(InputColumn.class));
    InputColumn inputColumn = (InputColumn) filterProjection.outputs().get(0);
    assertThat(inputColumn.index(), is(0));
    inputColumn = (InputColumn) filterProjection.outputs().get(1);
    assertThat(inputColumn.index(), is(1));
    MergePhase localMergeNode = planNode.mergePhase();
    assertThat(localMergeNode.projections().size(), is(1));
    assertThat(localMergeNode.projections().get(0), instanceOf(MergeCountProjection.class));
    assertThat(localMergeNode.finalProjection().get().outputs().size(), is(1));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) InputColumn(io.crate.analyze.symbol.InputColumn) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 20 with InputColumn

use of io.crate.analyze.symbol.InputColumn in project crate by crate.

the class AggregatorTest method testAggregationFromPartial.

@Test
public void testAggregationFromPartial() {
    Aggregation aggregation = Aggregation.finalAggregation(countImpl.info(), Collections.<Symbol>singletonList(new InputColumn(0)), Aggregation.Step.PARTIAL);
    Input dummyInput = new Input() {

        CountAggregation.LongState state = new CountAggregation.LongState(10L);

        @Override
        public Object value() {
            return state;
        }
    };
    Aggregator aggregator = new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, countImpl, dummyInput);
    Object state = aggregator.prepareState();
    state = aggregator.processRow(state);
    state = aggregator.processRow(state);
    Object result = aggregator.finishCollect(state);
    assertThat((Long) result, is(20L));
}
Also used : CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Aggregation(io.crate.analyze.symbol.Aggregation) Input(io.crate.data.Input) InputColumn(io.crate.analyze.symbol.InputColumn) CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

InputColumn (io.crate.analyze.symbol.InputColumn)24 Test (org.junit.Test)18 CrateUnitTest (io.crate.test.integration.CrateUnitTest)17 Symbol (io.crate.analyze.symbol.Symbol)8 Reference (io.crate.metadata.Reference)5 CollectExpression (io.crate.operation.collect.CollectExpression)5 Aggregation (io.crate.analyze.symbol.Aggregation)4 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)4 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)3 StreamInput (org.elasticsearch.common.io.stream.StreamInput)3 Input (io.crate.data.Input)2 FunctionIdent (io.crate.metadata.FunctionIdent)2 FunctionInfo (io.crate.metadata.FunctionInfo)2 Routing (io.crate.metadata.Routing)2 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)2 Aggregator (io.crate.operation.aggregation.Aggregator)2 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)2 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)2 BytesRef (org.apache.lucene.util.BytesRef)2 TransportBulkCreateIndicesAction (org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction)2