Search in sources :

Example 1 with InputCollectExpression

use of io.crate.operation.collect.InputCollectExpression 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)

Example 2 with InputCollectExpression

use of io.crate.operation.collect.InputCollectExpression 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 3 with InputCollectExpression

use of io.crate.operation.collect.InputCollectExpression in project crate by crate.

the class AggregationTest method executeAggregation.

public Object[][] executeAggregation(String name, DataType dataType, Object[][] data, List<DataType> argumentTypes) throws Exception {
    FunctionIdent fi;
    InputCollectExpression[] inputs;
    if (dataType != null) {
        fi = new FunctionIdent(name, argumentTypes);
        inputs = new InputCollectExpression[argumentTypes.size()];
        for (int i = 0; i < argumentTypes.size(); i++) {
            inputs[i] = new InputCollectExpression(i);
        }
    } else {
        fi = new FunctionIdent(name, ImmutableList.<DataType>of());
        inputs = new InputCollectExpression[0];
    }
    AggregationFunction impl = (AggregationFunction) functions.get(fi);
    Object state = impl.newState(ramAccountingContext);
    ArrayBucket bucket = new ArrayBucket(data);
    for (Row row : bucket) {
        for (InputCollectExpression i : inputs) {
            i.setNextRow(row);
        }
        state = impl.iterate(ramAccountingContext, state, inputs);
    }
    state = impl.terminatePartial(ramAccountingContext, state);
    return new Object[][] { { state } };
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) FunctionIdent(io.crate.metadata.FunctionIdent) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) DataType(io.crate.types.DataType) Row(io.crate.data.Row)

Example 4 with InputCollectExpression

use of io.crate.operation.collect.InputCollectExpression in project crate by crate.

the class GroupingBytesRefCollectorBenchmark method createGroupByMinBytesRefCollector.

private GroupingCollector createGroupByMinBytesRefCollector(Functions functions) {
    InputCollectExpression keyInput = new InputCollectExpression(0);
    List<Input<?>> keyInputs = Arrays.<Input<?>>asList(keyInput);
    CollectExpression[] collectExpressions = new CollectExpression[] { keyInput };
    FunctionIdent minBytesRefFuncIdent = new FunctionIdent(MinimumAggregation.NAME, Arrays.asList(DataTypes.STRING));
    FunctionInfo minBytesRefFuncInfo = new FunctionInfo(minBytesRefFuncIdent, DataTypes.INTEGER, FunctionInfo.Type.AGGREGATE);
    AggregationFunction minAgg = (AggregationFunction) functions.get(minBytesRefFuncIdent);
    Aggregation aggregation = Aggregation.finalAggregation(minBytesRefFuncInfo, Arrays.asList(new InputColumn(0)), Aggregation.Step.ITER);
    Aggregator[] aggregators = new Aggregator[] { new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, minAgg, new Input[] { keyInput }) };
    return GroupingCollector.singleKey(collectExpressions, aggregators, RAM_ACCOUNTING_CONTEXT, keyInputs.get(0), DataTypes.STRING);
}
Also used : AggregationFunction(io.crate.operation.aggregation.AggregationFunction) Aggregation(io.crate.analyze.symbol.Aggregation) MinimumAggregation(io.crate.operation.aggregation.impl.MinimumAggregation) 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 5 with InputCollectExpression

use of io.crate.operation.collect.InputCollectExpression in project crate by crate.

the class IndexWriterCountBatchIteratorTest method testIndexWriterIterator.

@Test
public void testIndexWriterIterator() throws Exception {
    execute("create table bulk_import (id int primary key) with (number_of_replicas=0)");
    ensureGreen();
    Supplier<BatchIterator> sourceSupplier = () -> RowsBatchIterator.newInstance(RowGenerator.fromSingleColValues(() -> IntStream.range(0, 10).mapToObj(i -> new BytesRef("{\"id\": " + i + "}")).iterator()), 1);
    Supplier<String> indexNameResolver = IndexNameResolver.forTable(new TableIdent(null, "bulk_import"));
    Input<?> sourceInput = new InputCollectExpression(0);
    List<CollectExpression<Row, ?>> collectExpressions = Collections.singletonList((InputCollectExpression) sourceInput);
    RowShardResolver rowShardResolver = getRowShardResolver();
    BulkShardProcessor bulkShardProcessor = getBulkShardProcessor();
    Supplier<ShardUpsertRequest.Item> updateItemSupplier = () -> new ShardUpsertRequest.Item(rowShardResolver.id(), null, new Object[] { sourceInput.value() }, null);
    List<Object[]> expectedResult = Collections.singletonList(new Object[] { 10L });
    BatchIteratorTester tester = new BatchIteratorTester(() -> IndexWriterCountBatchIterator.newIndexInstance(sourceSupplier.get(), indexNameResolver, collectExpressions, rowShardResolver, bulkShardProcessor, updateItemSupplier));
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : CrateSettings(io.crate.metadata.settings.CrateSettings) TransportBulkCreateIndicesAction(org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction) IntStream(java.util.stream.IntStream) Input(io.crate.data.Input) Arrays(java.util.Arrays) BulkShardProcessor(org.elasticsearch.action.bulk.BulkShardProcessor) InputColumn(io.crate.analyze.symbol.InputColumn) BatchIterator(io.crate.data.BatchIterator) BatchIteratorTester(io.crate.testing.BatchIteratorTester) Supplier(java.util.function.Supplier) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) CollectExpression(io.crate.operation.collect.CollectExpression) Settings(org.elasticsearch.common.settings.Settings) Symbol(io.crate.analyze.symbol.Symbol) ClusterService(org.elasticsearch.cluster.ClusterService) io.crate.metadata(io.crate.metadata) DocSysColumns(io.crate.metadata.doc.DocSysColumns) RowsBatchIterator(io.crate.data.RowsBatchIterator) RowShardResolver(io.crate.operation.collect.RowShardResolver) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) UUID(java.util.UUID) RowGenerator(io.crate.testing.RowGenerator) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) TransportShardUpsertAction(io.crate.executor.transport.TransportShardUpsertAction) List(java.util.List) Row(io.crate.data.Row) DataTypes(io.crate.types.DataTypes) BulkRetryCoordinatorPool(org.elasticsearch.action.bulk.BulkRetryCoordinatorPool) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) Collections(java.util.Collections) BatchIterator(io.crate.data.BatchIterator) RowsBatchIterator(io.crate.data.RowsBatchIterator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BulkShardProcessor(org.elasticsearch.action.bulk.BulkShardProcessor) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BatchIteratorTester(io.crate.testing.BatchIteratorTester) BytesRef(org.apache.lucene.util.BytesRef) RowShardResolver(io.crate.operation.collect.RowShardResolver) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Aggregations

InputCollectExpression (io.crate.operation.collect.InputCollectExpression)6 InputColumn (io.crate.analyze.symbol.InputColumn)5 CollectExpression (io.crate.operation.collect.CollectExpression)5 FunctionIdent (io.crate.metadata.FunctionIdent)3 BytesRef (org.apache.lucene.util.BytesRef)3 TransportBulkCreateIndicesAction (org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction)3 BulkRetryCoordinatorPool (org.elasticsearch.action.bulk.BulkRetryCoordinatorPool)3 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)3 Test (org.junit.Test)3 Aggregation (io.crate.analyze.symbol.Aggregation)2 BatchIterator (io.crate.data.BatchIterator)2 Row (io.crate.data.Row)2 RowsBatchIterator (io.crate.data.RowsBatchIterator)2 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)2 FunctionInfo (io.crate.metadata.FunctionInfo)2 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)2 Aggregator (io.crate.operation.aggregation.Aggregator)2 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)2 ClusterService (org.elasticsearch.cluster.ClusterService)2 Symbol (io.crate.analyze.symbol.Symbol)1