Search in sources :

Example 1 with FileWriterProjector

use of io.crate.execution.engine.export.FileWriterProjector 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(context.txnCtx);
    List<Input<?>> inputs = null;
    if (!projection.inputs().isEmpty()) {
        ctx.add(projection.inputs());
        inputs = ctx.topLevelInputs();
    }
    projection = projection.normalize(normalizer, context.txnCtx);
    String uri = DataTypes.STRING.sanitizeValue(SymbolEvaluator.evaluate(context.txnCtx, nodeCtx, projection.uri(), Row.EMPTY, SubQueryResults.EMPTY));
    assert uri != null : "URI must not be null";
    StringBuilder sb = new StringBuilder(uri);
    Symbol resolvedFileName = normalizer.normalize(WriterProjection.DIRECTORY_TO_FILENAME, context.txnCtx);
    assert resolvedFileName instanceof Literal : "resolvedFileName must be a Literal, but is: " + resolvedFileName;
    assert resolvedFileName.valueType().id() == StringType.ID : "resolvedFileName.valueType() must be " + StringType.INSTANCE;
    String fileName = (String) ((Literal) resolvedFileName).value();
    if (!uri.endsWith("/")) {
        sb.append("/");
    }
    sb.append(fileName);
    if (projection.compressionType() == WriterProjection.CompressionType.GZIP) {
        sb.append(".gz");
    }
    uri = sb.toString();
    Map<ColumnIdent, Object> overwrites = symbolMapToObject(projection.overwrites(), ctx, context.txnCtx);
    return new FileWriterProjector(threadPool.generic(), uri, projection.compressionType(), inputs, ctx.expressions(), overwrites, projection.outputNames(), projection.outputFormat(), fileOutputFactoryMap, projection.withClauseOptions());
}
Also used : InputFactory(io.crate.expression.InputFactory) Symbol(io.crate.expression.symbol.Symbol) NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) CollectExpression(io.crate.execution.engine.collect.CollectExpression) ColumnIdent(io.crate.metadata.ColumnIdent) Input(io.crate.data.Input) FileWriterProjector(io.crate.execution.engine.export.FileWriterProjector) Literal(io.crate.expression.symbol.Literal)

Aggregations

Input (io.crate.data.Input)1 CollectExpression (io.crate.execution.engine.collect.CollectExpression)1 NestableCollectExpression (io.crate.execution.engine.collect.NestableCollectExpression)1 FileWriterProjector (io.crate.execution.engine.export.FileWriterProjector)1 InputFactory (io.crate.expression.InputFactory)1 Literal (io.crate.expression.symbol.Literal)1 Symbol (io.crate.expression.symbol.Symbol)1 ColumnIdent (io.crate.metadata.ColumnIdent)1