Search in sources :

Example 1 with KudtfFlatMapper

use of io.confluent.ksql.execution.function.udtf.KudtfFlatMapper in project ksql by confluentinc.

the class StreamFlatMapBuilder method build.

public static <K> KStreamHolder<K> build(final KStreamHolder<K> stream, final StreamFlatMap<K> step, final RuntimeBuildContext buildContext) {
    final List<FunctionCall> tableFunctions = step.getTableFunctions();
    final LogicalSchema schema = stream.getSchema();
    final Builder<TableFunctionApplier> tableFunctionAppliersBuilder = ImmutableList.builder();
    final CodeGenRunner codeGenRunner = new CodeGenRunner(schema, buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
    for (final FunctionCall functionCall : tableFunctions) {
        final List<CompiledExpression> compiledExpressionList = new ArrayList<>(functionCall.getArguments().size());
        for (final Expression expression : functionCall.getArguments()) {
            final CompiledExpression compiledExpression = codeGenRunner.buildCodeGenFromParseTree(expression, "Table function");
            compiledExpressionList.add(compiledExpression);
        }
        final KsqlTableFunction tableFunction = UdtfUtil.resolveTableFunction(buildContext.getFunctionRegistry(), functionCall, schema);
        final TableFunctionApplier tableFunctionApplier = new TableFunctionApplier(tableFunction, compiledExpressionList);
        tableFunctionAppliersBuilder.add(tableFunctionApplier);
    }
    final QueryContext queryContext = step.getProperties().getQueryContext();
    final ProcessingLogger processingLogger = buildContext.getProcessingLogger(queryContext);
    final ImmutableList<TableFunctionApplier> tableFunctionAppliers = tableFunctionAppliersBuilder.build();
    final KStream<K, GenericRow> mapped = stream.getStream().flatTransformValues(() -> new KsTransformer<>(new KudtfFlatMapper<>(tableFunctionAppliers, processingLogger)), Named.as(StreamsUtil.buildOpName(queryContext)));
    return stream.withStream(mapped, buildSchema(stream.getSchema(), step.getTableFunctions(), buildContext.getFunctionRegistry()));
}
Also used : ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) ArrayList(java.util.ArrayList) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) QueryContext(io.confluent.ksql.execution.context.QueryContext) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) GenericRow(io.confluent.ksql.GenericRow) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) KsqlTableFunction(io.confluent.ksql.function.KsqlTableFunction) TableFunctionApplier(io.confluent.ksql.execution.function.udtf.TableFunctionApplier) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) KudtfFlatMapper(io.confluent.ksql.execution.function.udtf.KudtfFlatMapper)

Aggregations

GenericRow (io.confluent.ksql.GenericRow)1 CodeGenRunner (io.confluent.ksql.execution.codegen.CodeGenRunner)1 CompiledExpression (io.confluent.ksql.execution.codegen.CompiledExpression)1 QueryContext (io.confluent.ksql.execution.context.QueryContext)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)1 KudtfFlatMapper (io.confluent.ksql.execution.function.udtf.KudtfFlatMapper)1 TableFunctionApplier (io.confluent.ksql.execution.function.udtf.TableFunctionApplier)1 KsqlTableFunction (io.confluent.ksql.function.KsqlTableFunction)1 ProcessingLogger (io.confluent.ksql.logging.processing.ProcessingLogger)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 ArrayList (java.util.ArrayList)1