Search in sources :

Example 1 with IndexWriterProjector

use of io.crate.execution.engine.indexing.IndexWriterProjector in project crate by crate.

the class ProjectionToProjectorVisitor method visitSourceIndexWriterProjection.

@Override
public Projector visitSourceIndexWriterProjection(SourceIndexWriterProjection projection, Context context) {
    InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns(context.txnCtx);
    List<Input<?>> partitionedByInputs = new ArrayList<>(projection.partitionedBySymbols().size());
    for (Symbol partitionedBySymbol : projection.partitionedBySymbols()) {
        partitionedByInputs.add(ctx.add(partitionedBySymbol));
    }
    Input<?> sourceInput = ctx.add(projection.rawSource());
    Supplier<String> indexNameResolver = IndexNameResolver.create(projection.tableIdent(), projection.partitionIdent(), partitionedByInputs);
    ClusterState state = clusterService.state();
    Settings tableSettings = TableSettingsResolver.get(state.getMetadata(), projection.tableIdent(), !projection.partitionedBySymbols().isEmpty());
    int targetTableNumShards = IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.get(tableSettings);
    int targetTableNumReplicas = NumberOfReplicas.fromSettings(tableSettings, state.getNodes().getSize());
    UpsertResultContext upsertResultContext;
    if (projection instanceof SourceIndexWriterReturnSummaryProjection) {
        upsertResultContext = UpsertResultContext.forReturnSummary(context.txnCtx, (SourceIndexWriterReturnSummaryProjection) projection, clusterService.localNode(), inputFactory);
    } else {
        upsertResultContext = UpsertResultContext.forRowCount();
    }
    return new IndexWriterProjector(clusterService, nodeJobsCounter, circuitBreakerService.getBreaker(HierarchyCircuitBreakerService.QUERY), context.ramAccounting, threadPool.scheduler(), threadPool.executor(ThreadPool.Names.SEARCH), context.txnCtx, nodeCtx, state.metadata().settings(), targetTableNumShards, targetTableNumReplicas, transportActionProvider.transportBulkCreateIndicesAction(), transportActionProvider.transportShardUpsertAction()::execute, indexNameResolver, projection.rawSourceReference(), projection.primaryKeys(), projection.ids(), projection.clusteredBy(), projection.clusteredByIdent(), sourceInput, ctx.expressions(), projection.bulkActions(), projection.includes(), projection.excludes(), projection.autoCreateIndices(), projection.overwriteDuplicates(), context.jobId, upsertResultContext, projection.failFast());
}
Also used : InputFactory(io.crate.expression.InputFactory) ClusterState(org.elasticsearch.cluster.ClusterState) UpsertResultContext(io.crate.execution.engine.indexing.UpsertResultContext) SourceIndexWriterReturnSummaryProjection(io.crate.execution.dsl.projection.SourceIndexWriterReturnSummaryProjection) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) CollectExpression(io.crate.execution.engine.collect.CollectExpression) IndexWriterProjector(io.crate.execution.engine.indexing.IndexWriterProjector) ColumnIndexWriterProjector(io.crate.execution.engine.indexing.ColumnIndexWriterProjector) Input(io.crate.data.Input) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Input (io.crate.data.Input)1 SourceIndexWriterReturnSummaryProjection (io.crate.execution.dsl.projection.SourceIndexWriterReturnSummaryProjection)1 CollectExpression (io.crate.execution.engine.collect.CollectExpression)1 NestableCollectExpression (io.crate.execution.engine.collect.NestableCollectExpression)1 ColumnIndexWriterProjector (io.crate.execution.engine.indexing.ColumnIndexWriterProjector)1 IndexWriterProjector (io.crate.execution.engine.indexing.IndexWriterProjector)1 UpsertResultContext (io.crate.execution.engine.indexing.UpsertResultContext)1 InputFactory (io.crate.expression.InputFactory)1 Symbol (io.crate.expression.symbol.Symbol)1 ArrayList (java.util.ArrayList)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 Settings (org.elasticsearch.common.settings.Settings)1