Search in sources :

Example 21 with InputColumn

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

the class AggregatorTest method testAggregationFromIterToFinal.

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

        @Override
        public Object value() {
            return 300L;
        }
    };
    Aggregator collector = new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, countImpl, dummyInput);
    Object state = collector.prepareState();
    for (int i = 0; i < 5; i++) {
        state = collector.processRow(state);
    }
    long result = (Long) collector.finishCollect(state);
    assertThat(result, is(5L));
}
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) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 22 with InputColumn

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

the class RowShardResolverTest method testNoPrimaryKeyButRouting.

@Test
public void testNoPrimaryKeyButRouting() {
    RowShardResolver rowShardResolver = new RowShardResolver(functions, ImmutableList.<ColumnIdent>of(), ImmutableList.<Symbol>of(), ID_IDENT, new InputColumn(1));
    rowShardResolver.setNextRow(row(1, "hoschi"));
    // auto-generated id, special routing
    assertNotNull(rowShardResolver.id());
    assertThat(rowShardResolver.routing(), is("hoschi"));
}
Also used : InputColumn(io.crate.analyze.symbol.InputColumn) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 23 with InputColumn

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

the class RowShardResolverTest method testPrimaryKeyAndRouting.

@Test
public void testPrimaryKeyAndRouting() {
    List<Symbol> primaryKeySymbols = ImmutableList.<Symbol>of(new InputColumn(0), new InputColumn(1));
    RowShardResolver rowShardResolver = new RowShardResolver(functions, ImmutableList.of(ci("id"), ci("foo")), primaryKeySymbols, ci("foo"), new InputColumn(1));
    rowShardResolver.setNextRow(row(1, "hoschi"));
    // compound encoded id, special routing
    assertThat(rowShardResolver.id(), is("AgZob3NjaGkBMQ=="));
    assertThat(rowShardResolver.routing(), is("hoschi"));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) InputColumn(io.crate.analyze.symbol.InputColumn) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 24 with InputColumn

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

the class RowShardResolverTest method testPrimaryKeyNullException.

@Test
public void testPrimaryKeyNullException() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("A primary key value must not be NULL");
    List<Symbol> primaryKeySymbols = ImmutableList.<Symbol>of(new InputColumn(0));
    RowShardResolver rowShardResolver = new RowShardResolver(functions, ImmutableList.of(ci("id")), primaryKeySymbols, null, null);
    rowShardResolver.setNextRow(row(new Object[] { null }));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) InputColumn(io.crate.analyze.symbol.InputColumn) 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