Search in sources :

Example 1 with InputColumn

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

the class GroupingIntegerCollectorBenchmark method createGroupBySumCollector.

private GroupingCollector createGroupBySumCollector(Functions functions) {
    InputCollectExpression keyInput = new InputCollectExpression(0);
    List<Input<?>> keyInputs = Arrays.<Input<?>>asList(keyInput);
    CollectExpression[] collectExpressions = new CollectExpression[] { keyInput };
    FunctionIdent functionIdent = new FunctionIdent(SumAggregation.NAME, Arrays.asList(DataTypes.INTEGER));
    FunctionInfo functionInfo = new FunctionInfo(functionIdent, DataTypes.INTEGER, FunctionInfo.Type.AGGREGATE);
    AggregationFunction sumAgg = (AggregationFunction) functions.get(functionIdent);
    Aggregation aggregation = Aggregation.finalAggregation(functionInfo, Arrays.asList(new InputColumn(0)), Aggregation.Step.ITER);
    Aggregator[] aggregators = new Aggregator[] { new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, sumAgg, new Input[] { keyInput }) };
    return GroupingCollector.singleKey(collectExpressions, aggregators, RAM_ACCOUNTING_CONTEXT, keyInputs.get(0), DataTypes.INTEGER);
}
Also used : AggregationFunction(io.crate.operation.aggregation.AggregationFunction) Aggregation(io.crate.analyze.symbol.Aggregation) SumAggregation(io.crate.operation.aggregation.impl.SumAggregation) FunctionIdent(io.crate.metadata.FunctionIdent) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) InputColumn(io.crate.analyze.symbol.InputColumn) FunctionInfo(io.crate.metadata.FunctionInfo) Aggregator(io.crate.operation.aggregation.Aggregator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression)

Example 2 with InputColumn

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

the class FilterProjectionTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    SqlExpressions sqlExpressions = new SqlExpressions(T3.SOURCES, T3.TR_1);
    FilterProjection p = new FilterProjection(sqlExpressions.normalize(sqlExpressions.asSymbol("a = 'foo'")), ImmutableList.of(new InputColumn(1)));
    p.requiredGranularity(RowGranularity.SHARD);
    BytesStreamOutput out = new BytesStreamOutput();
    Projection.toStream(p, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    FilterProjection p2 = (FilterProjection) Projection.fromStream(in);
    assertEquals(p, p2);
}
Also used : InputColumn(io.crate.analyze.symbol.InputColumn) StreamInput(org.elasticsearch.common.io.stream.StreamInput) SqlExpressions(io.crate.testing.SqlExpressions) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with InputColumn

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

the class WriterProjectionTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    WriterProjection p = new WriterProjection(ImmutableList.<Symbol>of(new InputColumn(1)), Literal.of("/foo.json"), WriterProjection.CompressionType.GZIP, MapBuilder.<ColumnIdent, Symbol>newMapBuilder().put(new ColumnIdent("partitionColumn"), Literal.of(1)).map(), ImmutableList.of("foo"), WriterProjection.OutputFormat.JSON_OBJECT);
    BytesStreamOutput out = new BytesStreamOutput();
    Projection.toStream(p, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    WriterProjection p2 = (WriterProjection) Projection.fromStream(in);
    assertEquals(p, p2);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) 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 4 with InputColumn

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

the class InsertFromSubQueryAnalyzerTest method testFromQueryWithOnDuplicateKeyValues.

@Test
public void testFromQueryWithOnDuplicateKeyValues() throws Exception {
    InsertFromSubQueryAnalyzedStatement statement = e.analyze("insert into users (id, name) (select id, name from users) " + "on duplicate key update name = substr(values (name), 1, 1)");
    Assert.assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
    for (Map.Entry<Reference, Symbol> entry : statement.onDuplicateKeyAssignments().entrySet()) {
        assertThat(entry.getKey(), isReference("name"));
        assertThat(entry.getValue(), isFunction(SubstrFunction.NAME));
        Function function = (Function) entry.getValue();
        assertThat(function.arguments().get(0), instanceOf(InputColumn.class));
        InputColumn inputColumn = (InputColumn) function.arguments().get(0);
        assertThat(inputColumn.index(), is(1));
        assertThat(inputColumn.valueType(), instanceOf(StringType.class));
    }
}
Also used : Function(io.crate.analyze.symbol.Function) SubstrFunction(io.crate.operation.scalar.SubstrFunction) StringType(io.crate.types.StringType) Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) InputColumn(io.crate.analyze.symbol.InputColumn) Map(java.util.Map) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with InputColumn

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

the class IndexWriterProjectorUnitTest method testNullPKValue.

@Test
public void testNullPKValue() throws Throwable {
    InputCollectExpression sourceInput = new InputCollectExpression(0);
    List<CollectExpression<Row, ?>> collectExpressions = Collections.<CollectExpression<Row, ?>>singletonList(sourceInput);
    final IndexWriterProjector indexWriter = new IndexWriterProjector(clusterService, TestingHelpers.getFunctions(), new IndexNameExpressionResolver(Settings.EMPTY), Settings.EMPTY, mock(TransportBulkCreateIndicesAction.class), mock(BulkRequestExecutor.class), () -> "foo", mock(BulkRetryCoordinatorPool.class, Answers.RETURNS_DEEP_STUBS.get()), rawSourceReference, ImmutableList.of(ID_IDENT), Arrays.<Symbol>asList(new InputColumn(1)), null, null, sourceInput, collectExpressions, 20, null, null, false, false, UUID.randomUUID());
    RowN rowN = new RowN(new Object[] { new BytesRef("{\"y\": \"x\"}"), null });
    BatchIterator batchIterator = RowsBatchIterator.newInstance(Collections.singletonList(rowN), rowN.numColumns());
    batchIterator = indexWriter.apply(batchIterator);
    TestingBatchConsumer testingBatchConsumer = new TestingBatchConsumer();
    testingBatchConsumer.accept(batchIterator, null);
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("A primary key value must not be NULL");
    testingBatchConsumer.getResult();
}
Also used : BatchIterator(io.crate.data.BatchIterator) RowsBatchIterator(io.crate.data.RowsBatchIterator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BulkRetryCoordinatorPool(org.elasticsearch.action.bulk.BulkRetryCoordinatorPool) RowN(io.crate.data.RowN) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BulkRequestExecutor(org.elasticsearch.action.bulk.BulkRequestExecutor) InputColumn(io.crate.analyze.symbol.InputColumn) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportBulkCreateIndicesAction(org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction) BytesRef(org.apache.lucene.util.BytesRef) 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