Search in sources :

Example 21 with CollectExpression

use of io.crate.execution.engine.collect.CollectExpression in project crate by crate.

the class InputFactoryTest method testProcessGroupByProjectionSymbols.

@Test
public void testProcessGroupByProjectionSymbols() throws Exception {
    // select x, y * 2 ... group by x, y * 2
    // keys: [ in(0), in(1) + 10 ]
    List<Symbol> keys = Arrays.asList(new InputColumn(0, DataTypes.LONG), add);
    InputFactory.Context<CollectExpression<Row, ?>> ctx = factory.ctxForAggregations(txnCtx);
    ctx.add(keys);
    ArrayList<CollectExpression<Row, ?>> expressions = new ArrayList<>(ctx.expressions());
    assertThat(expressions.size(), is(2));
    // keyExpressions: [ in0, in1 ]
    RowN row = new RowN(1L, 2L);
    for (CollectExpression<Row, ?> expression : expressions) {
        expression.setNextRow(row);
    }
    assertThat(expressions.get(0).value(), is(1L));
    // raw input value
    assertThat(expressions.get(1).value(), is(2L));
    // inputs: [ x, add ]
    List<Input<?>> inputs = ctx.topLevelInputs();
    assertThat(inputs.size(), is(2));
    assertThat(inputs.get(0).value(), is(1L));
    // + 10
    assertThat(inputs.get(1).value(), is(12));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) CollectExpression(io.crate.execution.engine.collect.CollectExpression) RowN(io.crate.data.RowN) Input(io.crate.data.Input) InputColumn(io.crate.expression.symbol.InputColumn) Row(io.crate.data.Row) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

CollectExpression (io.crate.execution.engine.collect.CollectExpression)21 Input (io.crate.data.Input)15 InputFactory (io.crate.expression.InputFactory)12 Symbol (io.crate.expression.symbol.Symbol)12 ArrayList (java.util.ArrayList)11 Row (io.crate.data.Row)9 InputColumn (io.crate.expression.symbol.InputColumn)8 RowN (io.crate.data.RowN)7 Reference (io.crate.metadata.Reference)7 List (java.util.List)6 ClusterState (org.elasticsearch.cluster.ClusterState)6 InputCollectExpression (io.crate.execution.engine.collect.InputCollectExpression)5 NestableCollectExpression (io.crate.execution.engine.collect.NestableCollectExpression)5 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)5 OrderBy (io.crate.analyze.OrderBy)4 RamAccounting (io.crate.breaker.RamAccounting)4 InMemoryBatchIterator (io.crate.data.InMemoryBatchIterator)4 Function (io.crate.expression.symbol.Function)4 DataType (io.crate.types.DataType)4 Test (org.junit.Test)4