Search in sources :

Example 1 with KsqlTableFunction

use of io.confluent.ksql.function.KsqlTableFunction 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)

Example 2 with KsqlTableFunction

use of io.confluent.ksql.function.KsqlTableFunction in project ksql by confluentinc.

the class StepSchemaResolverTest method givenTableFunction.

private void givenTableFunction(final String name, final SqlType returnType) {
    final KsqlTableFunction tableFunction = mock(KsqlTableFunction.class);
    when(functionRegistry.isTableFunction(FunctionName.of(name))).thenReturn(true);
    when(functionRegistry.getTableFunction(eq(FunctionName.of(name)), any())).thenReturn(tableFunction);
    when(tableFunction.getReturnType(any())).thenReturn(returnType);
}
Also used : KsqlTableFunction(io.confluent.ksql.function.KsqlTableFunction)

Aggregations

KsqlTableFunction (io.confluent.ksql.function.KsqlTableFunction)2 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 ProcessingLogger (io.confluent.ksql.logging.processing.ProcessingLogger)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 ArrayList (java.util.ArrayList)1