Search in sources :

Example 11 with CollectExpression

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

the class ProjectionToProjectorVisitor method visitWriterProjection.

@Override
public Projector visitWriterProjection(WriterProjection projection, Context context) {
    InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns();
    List<Input<?>> inputs = null;
    if (!projection.inputs().isEmpty()) {
        ctx.add(projection.inputs());
        inputs = ctx.topLevelInputs();
    }
    Map<ColumnIdent, Object> overwrites = symbolMapToObject(projection.overwrites(), ctx, context.transactionContext);
    projection = projection.normalize(normalizer, context.transactionContext);
    String uri = ValueSymbolVisitor.STRING.process(projection.uri());
    assert uri != null : "URI must not be null";
    StringBuilder sb = new StringBuilder(uri);
    Symbol resolvedFileName = normalizer.normalize(WriterProjection.DIRECTORY_TO_FILENAME, context.transactionContext);
    assert resolvedFileName instanceof Literal : "resolvedFileName must be a Literal, but is: " + resolvedFileName;
    assert resolvedFileName.valueType() == StringType.INSTANCE : "resolvedFileName.valueType() must be " + StringType.INSTANCE;
    String fileName = ValueSymbolVisitor.STRING.process(resolvedFileName);
    if (!uri.endsWith("/")) {
        sb.append("/");
    }
    sb.append(fileName);
    if (projection.compressionType() == WriterProjection.CompressionType.GZIP) {
        sb.append(".gz");
    }
    uri = sb.toString();
    return new FileWriterProjector(((ThreadPoolExecutor) threadPool.generic()), uri, projection.compressionType(), inputs, ctx.expressions(), overwrites, projection.outputNames(), projection.outputFormat());
}
Also used : InputFactory(io.crate.operation.InputFactory) Symbol(io.crate.analyze.symbol.Symbol) CollectExpression(io.crate.operation.collect.CollectExpression) Input(io.crate.data.Input) Literal(io.crate.analyze.symbol.Literal) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 12 with CollectExpression

use of io.crate.operation.collect.CollectExpression 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();
    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);
    return new IndexWriterProjector(clusterService, functions, indexNameExpressionResolver, clusterService.state().metaData().settings(), transportActionProvider.transportBulkCreateIndicesAction(), transportActionProvider.transportShardUpsertAction()::execute, indexNameResolver, bulkRetryCoordinatorPool, 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);
}
Also used : InputFactory(io.crate.operation.InputFactory) Input(io.crate.data.Input) Symbol(io.crate.analyze.symbol.Symbol) CollectExpression(io.crate.operation.collect.CollectExpression)

Example 13 with CollectExpression

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

the class ProjectionToProjectorVisitor method visitColumnIndexWriterProjection.

@Override
public Projector visitColumnIndexWriterProjection(ColumnIndexWriterProjection projection, Context context) {
    InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns();
    List<Input<?>> partitionedByInputs = new ArrayList<>(projection.partitionedBySymbols().size());
    for (Symbol partitionedBySymbol : projection.partitionedBySymbols()) {
        partitionedByInputs.add(ctx.add(partitionedBySymbol));
    }
    List<Input<?>> insertInputs = new ArrayList<>(projection.columnSymbols().size());
    for (Symbol symbol : projection.columnSymbols()) {
        insertInputs.add(ctx.add(symbol));
    }
    return new ColumnIndexWriterProjector(clusterService, functions, indexNameExpressionResolver, clusterService.state().metaData().settings(), IndexNameResolver.create(projection.tableIdent(), projection.partitionIdent(), partitionedByInputs), transportActionProvider, bulkRetryCoordinatorPool, projection.primaryKeys(), projection.ids(), projection.clusteredBy(), projection.clusteredByIdent(), projection.columnReferences(), insertInputs, ctx.expressions(), projection.onDuplicateKeyAssignments(), projection.bulkActions(), projection.autoCreateIndices(), context.jobId);
}
Also used : InputFactory(io.crate.operation.InputFactory) Input(io.crate.data.Input) Symbol(io.crate.analyze.symbol.Symbol) CollectExpression(io.crate.operation.collect.CollectExpression)

Aggregations

CollectExpression (io.crate.operation.collect.CollectExpression)13 InputColumn (io.crate.analyze.symbol.InputColumn)6 Input (io.crate.data.Input)6 Test (org.junit.Test)6 InputFactory (io.crate.operation.InputFactory)5 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)5 Symbol (io.crate.analyze.symbol.Symbol)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 Row (io.crate.data.Row)3 RowN (io.crate.data.RowN)3 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)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 Aggregation (io.crate.analyze.symbol.Aggregation)2 BatchIterator (io.crate.data.BatchIterator)2 RowsBatchIterator (io.crate.data.RowsBatchIterator)2 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)2 FunctionIdent (io.crate.metadata.FunctionIdent)2