use of io.confluent.ksql.execution.function.udtf.TableFunctionApplier 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()));
}
Aggregations