Search in sources :

Example 1 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class InsertFromValues method executeBulk.

@Override
public List<CompletableFuture<Long>> executeBulk(DependencyCarrier dependencies, PlannerContext plannerContext, List<Row> bulkParams, SubQueryResults subQueryResults) {
    DocTableInfo tableInfo = dependencies.schemas().getTableInfo(writerProjection.tableIdent(), Operation.INSERT);
    String[] updateColumnNames;
    Assignments assignments;
    if (writerProjection.onDuplicateKeyAssignments() == null) {
        assignments = null;
        updateColumnNames = null;
    } else {
        assignments = Assignments.convert(writerProjection.onDuplicateKeyAssignments(), dependencies.nodeContext());
        updateColumnNames = assignments.targetNames();
    }
    InputFactory inputFactory = new InputFactory(dependencies.nodeContext());
    InputFactory.Context<CollectExpression<Row, ?>> context = inputFactory.ctxForInputColumns(plannerContext.transactionContext());
    var allColumnSymbols = InputColumns.create(writerProjection.allTargetColumns(), new InputColumns.SourceSymbols(writerProjection.allTargetColumns()));
    ArrayList<Input<?>> insertInputs = new ArrayList<>(allColumnSymbols.size());
    for (Symbol symbol : allColumnSymbols) {
        insertInputs.add(context.add(symbol));
    }
    ArrayList<Input<?>> partitionedByInputs = new ArrayList<>(writerProjection.partitionedBySymbols().size());
    for (Symbol partitionedBySymbol : writerProjection.partitionedBySymbols()) {
        partitionedByInputs.add(context.add(partitionedBySymbol));
    }
    ArrayList<Input<?>> primaryKeyInputs = new ArrayList<>(writerProjection.ids().size());
    for (Symbol symbol : writerProjection.ids()) {
        primaryKeyInputs.add(context.add(symbol));
    }
    Input<?> clusterByInput;
    if (writerProjection.clusteredBy() != null) {
        clusterByInput = context.add(writerProjection.clusteredBy());
    } else {
        clusterByInput = null;
    }
    var indexNameResolver = IndexNameResolver.create(writerProjection.tableIdent(), writerProjection.partitionIdent(), partitionedByInputs);
    ShardUpsertRequest.Builder builder = new ShardUpsertRequest.Builder(plannerContext.transactionContext().sessionSettings(), BULK_REQUEST_TIMEOUT_SETTING.get(dependencies.settings()), writerProjection.isIgnoreDuplicateKeys() ? ShardUpsertRequest.DuplicateKeyAction.IGNORE : ShardUpsertRequest.DuplicateKeyAction.UPDATE_OR_FAIL, // continueOnErrors
    true, updateColumnNames, writerProjection.allTargetColumns().toArray(new Reference[0]), null, plannerContext.jobId(), true);
    var shardedRequests = new ShardedRequests<>(builder::newRequest, RamAccounting.NO_ACCOUNTING);
    HashMap<String, InsertSourceFromCells> validatorsCache = new HashMap<>();
    IntArrayList bulkIndices = new IntArrayList();
    List<CompletableFuture<Long>> results = createUnsetFutures(bulkParams.size());
    for (int bulkIdx = 0; bulkIdx < bulkParams.size(); bulkIdx++) {
        Row param = bulkParams.get(bulkIdx);
        final Symbol[] assignmentSources;
        if (assignments != null) {
            assignmentSources = assignments.bindSources(tableInfo, param, subQueryResults);
        } else {
            assignmentSources = null;
        }
        GroupRowsByShard<ShardUpsertRequest, ShardUpsertRequest.Item> grouper = createRowsByShardGrouper(assignmentSources, insertInputs, indexNameResolver, context, plannerContext, dependencies.clusterService());
        try {
            Iterator<Row> rows = evaluateValueTableFunction(tableFunctionRelation.functionImplementation(), tableFunctionRelation.function().arguments(), writerProjection.allTargetColumns(), tableInfo, param, plannerContext, subQueryResults);
            while (rows.hasNext()) {
                Row row = rows.next();
                grouper.accept(shardedRequests, row);
                checkPrimaryKeyValuesNotNull(primaryKeyInputs);
                checkClusterByValueNotNull(clusterByInput);
                checkConstraintsOnGeneratedSource(row.materialize(), indexNameResolver.get(), tableInfo, plannerContext, validatorsCache);
                bulkIndices.add(bulkIdx);
            }
        } catch (Throwable t) {
            for (CompletableFuture<Long> result : results) {
                result.completeExceptionally(t);
            }
            return results;
        }
    }
    validatorsCache.clear();
    var actionProvider = dependencies.transportActionProvider();
    createIndices(actionProvider.transportBulkCreateIndicesAction(), shardedRequests.itemsByMissingIndex().keySet(), dependencies.clusterService(), plannerContext.jobId()).thenCompose(acknowledgedResponse -> {
        var shardUpsertRequests = resolveAndGroupShardRequests(shardedRequests, dependencies.clusterService()).values();
        return execute(dependencies.nodeLimits(), dependencies.clusterService().state(), shardUpsertRequests, actionProvider.transportShardUpsertAction(), dependencies.scheduler());
    }).whenComplete((response, t) -> {
        if (t == null) {
            long[] resultRowCount = createBulkResponse(response, bulkParams.size(), bulkIndices);
            for (int i = 0; i < bulkParams.size(); i++) {
                results.get(i).complete(resultRowCount[i]);
            }
        } else {
            for (CompletableFuture<Long> result : results) {
                result.completeExceptionally(t);
            }
        }
    });
    return results;
}
Also used : GeneratedColumns(io.crate.execution.dml.upsert.GeneratedColumns) IndexParts(io.crate.metadata.IndexParts) INDEX_CLOSED_BLOCK(org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_CLOSED_BLOCK) Arrays(java.util.Arrays) TransportShardUpsertAction(io.crate.execution.dml.upsert.TransportShardUpsertAction) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardedRequests(io.crate.execution.engine.indexing.ShardedRequests) TableFunctionRelation(io.crate.analyze.relations.TableFunctionRelation) NodeLimits(io.crate.execution.jobs.NodeLimits) TransportCreatePartitionsAction(org.elasticsearch.action.admin.indices.create.TransportCreatePartitionsAction) RetryListener(io.crate.execution.support.RetryListener) DependencyCarrier(io.crate.planner.DependencyCarrier) ClusterState(org.elasticsearch.cluster.ClusterState) RowN(io.crate.data.RowN) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) TableStats(io.crate.statistics.TableStats) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntArrayList(com.carrotsearch.hppc.IntArrayList) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) TypeGuessEstimateRowSize(io.crate.breaker.TypeGuessEstimateRowSize) ConcurrencyLimit(io.crate.concurrent.limits.ConcurrencyLimit) SelectSymbol(io.crate.expression.symbol.SelectSymbol) GroupRowsByShard(io.crate.execution.engine.indexing.GroupRowsByShard) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Collection(java.util.Collection) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) Set(java.util.Set) UUID(java.util.UUID) InputRow(io.crate.expression.InputRow) ShardRequest(io.crate.execution.dml.ShardRequest) ExecutionPlan(io.crate.planner.ExecutionPlan) List(java.util.List) OrderBy(io.crate.analyze.OrderBy) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) RowShardResolver(io.crate.execution.engine.collect.RowShardResolver) Assignments(io.crate.expression.symbol.Assignments) Row1(io.crate.data.Row1) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Input(io.crate.data.Input) SENTINEL(io.crate.data.SentinelRow.SENTINEL) ClusterService(org.elasticsearch.cluster.service.ClusterService) CollectExpression(io.crate.execution.engine.collect.CollectExpression) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Operation(io.crate.metadata.table.Operation) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) InsertSourceFromCells(io.crate.execution.dml.upsert.InsertSourceFromCells) ArrayList(java.util.ArrayList) BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) Metadata(org.elasticsearch.cluster.metadata.Metadata) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ShardLocation(io.crate.execution.engine.indexing.ShardLocation) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSupport(java.util.stream.StreamSupport) ColumnValidationException(io.crate.exceptions.ColumnValidationException) Nullable(javax.annotation.Nullable) FutureActionListener(io.crate.action.FutureActionListener) ProjectionBuilder(io.crate.execution.dsl.projection.builder.ProjectionBuilder) BULK_REQUEST_TIMEOUT_SETTING(io.crate.execution.engine.indexing.ShardingUpsertExecutor.BULK_REQUEST_TIMEOUT_SETTING) Iterator(java.util.Iterator) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RamAccounting(io.crate.breaker.RamAccounting) Consumer(java.util.function.Consumer) RowConsumer(io.crate.data.RowConsumer) ShardResponse(io.crate.execution.dml.ShardResponse) ShardUpsertRequest(io.crate.execution.dml.upsert.ShardUpsertRequest) CollectionBucket(io.crate.data.CollectionBucket) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) IndexNameResolver(io.crate.execution.engine.indexing.IndexNameResolver) NotSerializableExceptionWrapper(org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper) AbstractTableRelation(io.crate.analyze.relations.AbstractTableRelation) PlannerContext(io.crate.planner.PlannerContext) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) SQLExceptions(io.crate.exceptions.SQLExceptions) InputFactory(io.crate.expression.InputFactory) CreatePartitionsRequest(org.elasticsearch.action.admin.indices.create.CreatePartitionsRequest) ActionListener(org.elasticsearch.action.ActionListener) InputFactory(io.crate.expression.InputFactory) DocTableInfo(io.crate.metadata.doc.DocTableInfo) HashMap(java.util.HashMap) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) ProjectionBuilder(io.crate.execution.dsl.projection.builder.ProjectionBuilder) Assignments(io.crate.expression.symbol.Assignments) IntArrayList(com.carrotsearch.hppc.IntArrayList) ArrayList(java.util.ArrayList) Input(io.crate.data.Input) CompletableFuture(java.util.concurrent.CompletableFuture) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) ShardUpsertRequest(io.crate.execution.dml.upsert.ShardUpsertRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) Reference(io.crate.metadata.Reference) CollectExpression(io.crate.execution.engine.collect.CollectExpression) InsertSourceFromCells(io.crate.execution.dml.upsert.InsertSourceFromCells) ShardedRequests(io.crate.execution.engine.indexing.ShardedRequests) InputRow(io.crate.expression.InputRow) Row(io.crate.data.Row) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 2 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class InsertFromValues method execute.

@Override
public void execute(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    DocTableInfo tableInfo = dependencies.schemas().getTableInfo(writerProjection.tableIdent(), Operation.INSERT);
    // For instance, the target table of the insert from values
    // statement is the table with the following schema:
    // 
    // CREATE TABLE users (
    // dep_id TEXT,
    // name TEXT,
    // id INT,
    // country_id INT,
    // PRIMARY KEY (dep_id, id, country_id))
    // CLUSTERED BY (dep_id)
    // PARTITIONED BY (country_id)
    // 
    // The insert from values statement below would have the column
    // index writer projection of its plan that contains the column
    // idents and symbols required to create corresponding inputs.
    // The diagram below shows the projection's column symbols used
    // in the plan and relation between symbols sub-/sets.
    // 
    // +------------------------+
    // |          +-------------+  PK symbols
    // cluster by +------+ |          |      +------+
    // symbol            | |          |      |
    // + +          +      +
    // INSERT INTO users (dep_id, name, id, country_id) VALUES (?, ?, ?, ?)
    // +      +    +     +   +
    // +-------+      |    |     |   |
    // all target  +--------------+    |     |   +---+  partitioned by
    // column      +-------------------+     |          symbols
    // symbols     +-------------------------+
    InputFactory inputFactory = new InputFactory(dependencies.nodeContext());
    InputFactory.Context<CollectExpression<Row, ?>> context = inputFactory.ctxForInputColumns(plannerContext.transactionContext());
    var allColumnSymbols = InputColumns.create(writerProjection.allTargetColumns(), new InputColumns.SourceSymbols(writerProjection.allTargetColumns()));
    ArrayList<Input<?>> insertInputs = new ArrayList<>(allColumnSymbols.size());
    for (Symbol symbol : allColumnSymbols) {
        insertInputs.add(context.add(symbol));
    }
    ArrayList<Input<?>> partitionedByInputs = new ArrayList<>(writerProjection.partitionedBySymbols().size());
    for (Symbol partitionedBySymbol : writerProjection.partitionedBySymbols()) {
        partitionedByInputs.add(context.add(partitionedBySymbol));
    }
    ArrayList<Input<?>> primaryKeyInputs = new ArrayList<>(writerProjection.ids().size());
    for (Symbol symbol : writerProjection.ids()) {
        primaryKeyInputs.add(context.add(symbol));
    }
    Input<?> clusterByInput;
    if (writerProjection.clusteredBy() != null) {
        clusterByInput = context.add(writerProjection.clusteredBy());
    } else {
        clusterByInput = null;
    }
    String[] updateColumnNames;
    Symbol[] assignmentSources;
    if (writerProjection.onDuplicateKeyAssignments() == null) {
        updateColumnNames = null;
        assignmentSources = null;
    } else {
        Assignments assignments = Assignments.convert(writerProjection.onDuplicateKeyAssignments(), dependencies.nodeContext());
        assignmentSources = assignments.bindSources(tableInfo, params, subQueryResults);
        updateColumnNames = assignments.targetNames();
    }
    var indexNameResolver = IndexNameResolver.create(writerProjection.tableIdent(), writerProjection.partitionIdent(), partitionedByInputs);
    GroupRowsByShard<ShardUpsertRequest, ShardUpsertRequest.Item> grouper = createRowsByShardGrouper(assignmentSources, insertInputs, indexNameResolver, context, plannerContext, dependencies.clusterService());
    ArrayList<Row> rows = new ArrayList<>();
    evaluateValueTableFunction(tableFunctionRelation.functionImplementation(), tableFunctionRelation.function().arguments(), writerProjection.allTargetColumns(), tableInfo, params, plannerContext, subQueryResults).forEachRemaining(rows::add);
    List<Symbol> returnValues = this.writerProjection.returnValues();
    ShardUpsertRequest.Builder builder = new ShardUpsertRequest.Builder(plannerContext.transactionContext().sessionSettings(), BULK_REQUEST_TIMEOUT_SETTING.get(dependencies.settings()), writerProjection.isIgnoreDuplicateKeys() ? ShardUpsertRequest.DuplicateKeyAction.IGNORE : ShardUpsertRequest.DuplicateKeyAction.UPDATE_OR_FAIL, // continueOnErrors
    rows.size() > 1, updateColumnNames, writerProjection.allTargetColumns().toArray(new Reference[0]), returnValues.isEmpty() ? null : returnValues.toArray(new Symbol[0]), plannerContext.jobId(), false);
    var shardedRequests = new ShardedRequests<>(builder::newRequest, RamAccounting.NO_ACCOUNTING);
    HashMap<String, InsertSourceFromCells> validatorsCache = new HashMap<>();
    for (Row row : rows) {
        grouper.accept(shardedRequests, row);
        try {
            checkPrimaryKeyValuesNotNull(primaryKeyInputs);
            checkClusterByValueNotNull(clusterByInput);
            checkConstraintsOnGeneratedSource(row.materialize(), indexNameResolver.get(), tableInfo, plannerContext, validatorsCache);
        } catch (Throwable t) {
            consumer.accept(null, t);
            return;
        }
    }
    validatorsCache.clear();
    var actionProvider = dependencies.transportActionProvider();
    createIndices(actionProvider.transportBulkCreateIndicesAction(), shardedRequests.itemsByMissingIndex().keySet(), dependencies.clusterService(), plannerContext.jobId()).thenCompose(acknowledgedResponse -> {
        var shardUpsertRequests = resolveAndGroupShardRequests(shardedRequests, dependencies.clusterService()).values();
        return execute(dependencies.nodeLimits(), dependencies.clusterService().state(), shardUpsertRequests, actionProvider.transportShardUpsertAction(), dependencies.scheduler());
    }).whenComplete((response, t) -> {
        if (t == null) {
            if (returnValues.isEmpty()) {
                consumer.accept(InMemoryBatchIterator.of(new Row1((long) response.numSuccessfulWrites()), SENTINEL), null);
            } else {
                consumer.accept(InMemoryBatchIterator.of(new CollectionBucket(response.resultRows()), SENTINEL, false), null);
            }
        } else {
            consumer.accept(null, t);
        }
    });
}
Also used : GeneratedColumns(io.crate.execution.dml.upsert.GeneratedColumns) IndexParts(io.crate.metadata.IndexParts) INDEX_CLOSED_BLOCK(org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_CLOSED_BLOCK) Arrays(java.util.Arrays) TransportShardUpsertAction(io.crate.execution.dml.upsert.TransportShardUpsertAction) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardedRequests(io.crate.execution.engine.indexing.ShardedRequests) TableFunctionRelation(io.crate.analyze.relations.TableFunctionRelation) NodeLimits(io.crate.execution.jobs.NodeLimits) TransportCreatePartitionsAction(org.elasticsearch.action.admin.indices.create.TransportCreatePartitionsAction) RetryListener(io.crate.execution.support.RetryListener) DependencyCarrier(io.crate.planner.DependencyCarrier) ClusterState(org.elasticsearch.cluster.ClusterState) RowN(io.crate.data.RowN) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) TableStats(io.crate.statistics.TableStats) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntArrayList(com.carrotsearch.hppc.IntArrayList) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) TypeGuessEstimateRowSize(io.crate.breaker.TypeGuessEstimateRowSize) ConcurrencyLimit(io.crate.concurrent.limits.ConcurrencyLimit) SelectSymbol(io.crate.expression.symbol.SelectSymbol) GroupRowsByShard(io.crate.execution.engine.indexing.GroupRowsByShard) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Collection(java.util.Collection) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) Set(java.util.Set) UUID(java.util.UUID) InputRow(io.crate.expression.InputRow) ShardRequest(io.crate.execution.dml.ShardRequest) ExecutionPlan(io.crate.planner.ExecutionPlan) List(java.util.List) OrderBy(io.crate.analyze.OrderBy) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) RowShardResolver(io.crate.execution.engine.collect.RowShardResolver) Assignments(io.crate.expression.symbol.Assignments) Row1(io.crate.data.Row1) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Input(io.crate.data.Input) SENTINEL(io.crate.data.SentinelRow.SENTINEL) ClusterService(org.elasticsearch.cluster.service.ClusterService) CollectExpression(io.crate.execution.engine.collect.CollectExpression) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Operation(io.crate.metadata.table.Operation) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) InsertSourceFromCells(io.crate.execution.dml.upsert.InsertSourceFromCells) ArrayList(java.util.ArrayList) BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) Metadata(org.elasticsearch.cluster.metadata.Metadata) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ShardLocation(io.crate.execution.engine.indexing.ShardLocation) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSupport(java.util.stream.StreamSupport) ColumnValidationException(io.crate.exceptions.ColumnValidationException) Nullable(javax.annotation.Nullable) FutureActionListener(io.crate.action.FutureActionListener) ProjectionBuilder(io.crate.execution.dsl.projection.builder.ProjectionBuilder) BULK_REQUEST_TIMEOUT_SETTING(io.crate.execution.engine.indexing.ShardingUpsertExecutor.BULK_REQUEST_TIMEOUT_SETTING) Iterator(java.util.Iterator) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RamAccounting(io.crate.breaker.RamAccounting) Consumer(java.util.function.Consumer) RowConsumer(io.crate.data.RowConsumer) ShardResponse(io.crate.execution.dml.ShardResponse) ShardUpsertRequest(io.crate.execution.dml.upsert.ShardUpsertRequest) CollectionBucket(io.crate.data.CollectionBucket) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) IndexNameResolver(io.crate.execution.engine.indexing.IndexNameResolver) NotSerializableExceptionWrapper(org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper) AbstractTableRelation(io.crate.analyze.relations.AbstractTableRelation) PlannerContext(io.crate.planner.PlannerContext) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) SQLExceptions(io.crate.exceptions.SQLExceptions) InputFactory(io.crate.expression.InputFactory) CreatePartitionsRequest(org.elasticsearch.action.admin.indices.create.CreatePartitionsRequest) ActionListener(org.elasticsearch.action.ActionListener) InputFactory(io.crate.expression.InputFactory) DocTableInfo(io.crate.metadata.doc.DocTableInfo) HashMap(java.util.HashMap) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) ProjectionBuilder(io.crate.execution.dsl.projection.builder.ProjectionBuilder) IntArrayList(com.carrotsearch.hppc.IntArrayList) ArrayList(java.util.ArrayList) Assignments(io.crate.expression.symbol.Assignments) Row1(io.crate.data.Row1) Input(io.crate.data.Input) CollectionBucket(io.crate.data.CollectionBucket) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) ShardUpsertRequest(io.crate.execution.dml.upsert.ShardUpsertRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) Reference(io.crate.metadata.Reference) CollectExpression(io.crate.execution.engine.collect.CollectExpression) InsertSourceFromCells(io.crate.execution.dml.upsert.InsertSourceFromCells) ShardedRequests(io.crate.execution.engine.indexing.ShardedRequests) InputRow(io.crate.expression.InputRow) Row(io.crate.data.Row)

Example 3 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class CsvReaderBenchmark method create_temp_file_and_uri.

@Setup
public void create_temp_file_and_uri() throws IOException {
    NodeContext nodeCtx = new NodeContext(new Functions(Map.of()));
    inputFactory = new InputFactory(nodeCtx);
    tempFile = File.createTempFile("temp", null);
    fileUri = tempFile.toURI().getPath();
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8)) {
        writer.write("name,id\n");
        writer.write("Arthur,4\n");
        writer.write("Trillian,5\n");
        writer.write("Emma,5\n");
        writer.write("Emily,9\n");
        writer.write("Sarah,5\n");
        writer.write("John,5\n");
        writer.write("Mical,9\n");
        writer.write("Mary,5\n");
        writer.write("Jimmy,9\n");
        writer.write("Tom,5\n");
        writer.write("Neil,0\n");
        writer.write("Rose,5\n");
        writer.write("Gobnait,5\n");
        writer.write("Rory,1\n");
        writer.write("Martin,11\n");
        writer.write("Arthur,4\n");
        writer.write("Trillian,5\n");
        writer.write("Emma,5\n");
        writer.write("Emily,9\n");
        writer.write("Sarah,5\n");
        writer.write("John,5\n");
        writer.write("Mical,9\n");
        writer.write("Mary,5\n");
        writer.write("Jimmy,9\n");
        writer.write("Tom,5\n");
        writer.write("Neil,0\n");
        writer.write("Rose,5\n");
        writer.write("Gobnait,5\n");
        writer.write("Rory,1\n");
        writer.write("Martin,11\n");
    }
}
Also used : LocalFsFileInputFactory(io.crate.execution.engine.collect.files.LocalFsFileInputFactory) InputFactory(io.crate.expression.InputFactory) NodeContext(io.crate.metadata.NodeContext) FileOutputStream(java.io.FileOutputStream) Functions(io.crate.metadata.Functions) OutputStreamWriter(java.io.OutputStreamWriter) Setup(org.openjdk.jmh.annotations.Setup)

Example 4 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class JsonReaderBenchmark method create_temp_file_and_uri.

@Setup
public void create_temp_file_and_uri() throws IOException {
    NodeContext nodeCtx = new NodeContext(new Functions(Map.of()));
    inputFactory = new InputFactory(nodeCtx);
    tempFile = File.createTempFile("temp", null);
    fileUri = tempFile.toURI().getPath();
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8)) {
        writer.write("{\"name\": \"Arthur\", \"id\": 4\\n");
        writer.write("{\"id\": 5, \"name\": \"Trillian\"\n");
        writer.write("{\"id\": 5, \"name\": \"Emma\"\n");
        writer.write("{\"id\": 9, \"name\": \"Emily\"\n");
        writer.write("{\"id\": 5, \"name\": \"Sarah\"\n");
        writer.write("{\"id\": 5, \"name\": \"John\"\n");
        writer.write("{\"id\": 9, \"name\": \"Mical\"\n");
        writer.write("{\"id\": 5, \"name\": \"Mary\"\n");
        writer.write("{\"id\": 9, \"name\": \"Jimmy\"\n");
        writer.write("{\"id\": 5, \"name\": \"Tom\"\n");
        writer.write("{\"id\": 0, \"name\": \"Neil\"\n");
        writer.write("{\"id\": 5, \"name\": \"Rose\"\n");
        writer.write("{\"id\": 5, \"name\": \"Gobnait\"\n");
        writer.write("{\"id\": 1, \"name\": \"Rory\"\n");
        writer.write("{\"id\": 11, \"name\": \"Martin\"\n");
        writer.write("{\"id\": 5, \"name\": \"Trillian\"\n");
        writer.write("{\"id\": 5, \"name\": \"Emma\"\n");
        writer.write("{\"id\": 9, \"name\": \"Emily\"\n");
        writer.write("{\"id\": 5, \"name\": \"Sarah\"\n");
        writer.write("{\"id\": 5, \"name\": \"John\"\n");
        writer.write("{\"id\": 9, \"name\": \"Mical\"\n");
        writer.write("{\"id\": 5, \"name\": \"Mary\"\n");
        writer.write("{\"id\": 9, \"name\": \"Jimmy\"\n");
        writer.write("{\"id\": 5, \"name\": \"Tom\"\n");
        writer.write("{\"id\": 0, \"name\": \"Neil\"\n");
        writer.write("{\"id\": 5, \"name\": \"Rose\"\n");
        writer.write("{\"id\": 5, \"name\": \"Gobnait\"\n");
        writer.write("{\"id\": 1, \"name\": \"Rory\"\n");
        writer.write("{\"id\": 11, \"name\": \"Martin\"\n");
    }
}
Also used : LocalFsFileInputFactory(io.crate.execution.engine.collect.files.LocalFsFileInputFactory) InputFactory(io.crate.expression.InputFactory) NodeContext(io.crate.metadata.NodeContext) FileOutputStream(java.io.FileOutputStream) Functions(io.crate.metadata.Functions) OutputStreamWriter(java.io.OutputStreamWriter) Setup(org.openjdk.jmh.annotations.Setup)

Example 5 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class LuceneShardCollectorProvider method getProjectionFusedIterator.

@Nullable
@Override
protected BatchIterator<Row> getProjectionFusedIterator(RoutedCollectPhase normalizedPhase, CollectTask collectTask) {
    var it = GroupByOptimizedIterator.tryOptimizeSingleStringKey(indexShard, table, luceneQueryBuilder, fieldTypeLookup, bigArrays, new InputFactory(nodeCtx), docInputFactory, normalizedPhase, collectTask);
    if (it != null) {
        return it;
    }
    it = DocValuesGroupByOptimizedIterator.tryOptimize(nodeCtx.functions(), indexShard, table, luceneQueryBuilder, fieldTypeLookup, docInputFactory, normalizedPhase, collectTask);
    if (it != null) {
        return it;
    }
    return DocValuesAggregates.tryOptimize(nodeCtx.functions(), indexShard, table, luceneQueryBuilder, normalizedPhase, collectTask);
}
Also used : InputFactory(io.crate.expression.InputFactory) Nullable(javax.annotation.Nullable)

Aggregations

InputFactory (io.crate.expression.InputFactory)26 Symbol (io.crate.expression.symbol.Symbol)13 ArrayList (java.util.ArrayList)13 Before (org.junit.Before)10 RamAccounting (io.crate.breaker.RamAccounting)8 Input (io.crate.data.Input)8 NodeContext (io.crate.metadata.NodeContext)8 Test (org.junit.Test)8 Row (io.crate.data.Row)7 OrderBy (io.crate.analyze.OrderBy)6 BatchIterator (io.crate.data.BatchIterator)6 CollectExpression (io.crate.execution.engine.collect.CollectExpression)6 Reference (io.crate.metadata.Reference)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 Nullable (javax.annotation.Nullable)6 InMemoryBatchIterator (io.crate.data.InMemoryBatchIterator)5 SENTINEL (io.crate.data.SentinelRow.SENTINEL)5 NodeLimits (io.crate.execution.jobs.NodeLimits)5 InputColumn (io.crate.expression.symbol.InputColumn)5 Functions (io.crate.metadata.Functions)5