Search in sources :

Example 1 with CodeGenRunner

use of io.confluent.ksql.codegen.CodeGenRunner in project ksql by confluentinc.

the class SelectValueMapperTest method createExpressionMetadata.

private List<ExpressionMetadata> createExpressionMetadata(final List<Pair<String, Expression>> expressionPairList, final Schema schema) throws Exception {
    final CodeGenRunner codeGenRunner = new CodeGenRunner(schema, new FunctionRegistry());
    final List<ExpressionMetadata> expressionEvaluators = new ArrayList<>();
    for (Pair<String, Expression> expressionPair : expressionPairList) {
        final ExpressionMetadata expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(expressionPair.getRight());
        expressionEvaluators.add(expressionEvaluator);
    }
    return expressionEvaluators;
}
Also used : ExpressionMetadata(io.confluent.ksql.util.ExpressionMetadata) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) CodeGenRunner(io.confluent.ksql.codegen.CodeGenRunner) Expression(io.confluent.ksql.parser.tree.Expression) ArrayList(java.util.ArrayList)

Example 2 with CodeGenRunner

use of io.confluent.ksql.codegen.CodeGenRunner in project ksql by confluentinc.

the class SchemaKStream method createSelectValueMapperAndSchema.

Pair<Schema, SelectValueMapper> createSelectValueMapperAndSchema(final List<Pair<String, Expression>> expressionPairList) {
    try {
        final CodeGenRunner codeGenRunner = new CodeGenRunner(schema, functionRegistry);
        final SchemaBuilder schemaBuilder = SchemaBuilder.struct();
        final List<ExpressionMetadata> expressionEvaluators = new ArrayList<>();
        for (Pair<String, Expression> expressionPair : expressionPairList) {
            final ExpressionMetadata expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(expressionPair.getRight());
            schemaBuilder.field(expressionPair.getLeft(), expressionEvaluator.getExpressionType());
            expressionEvaluators.add(expressionEvaluator);
        }
        return new Pair<>(schemaBuilder.build(), new SelectValueMapper(genericRowValueTypeEnforcer, expressionPairList, expressionEvaluators));
    } catch (Exception e) {
        throw new KsqlException("Code generation failed for SelectValueMapper", e);
    }
}
Also used : ExpressionMetadata(io.confluent.ksql.util.ExpressionMetadata) CodeGenRunner(io.confluent.ksql.codegen.CodeGenRunner) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Expression(io.confluent.ksql.parser.tree.Expression) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) ArrayList(java.util.ArrayList) KsqlException(io.confluent.ksql.util.KsqlException) KsqlException(io.confluent.ksql.util.KsqlException) Pair(io.confluent.ksql.util.Pair)

Aggregations

CodeGenRunner (io.confluent.ksql.codegen.CodeGenRunner)2 Expression (io.confluent.ksql.parser.tree.Expression)2 ExpressionMetadata (io.confluent.ksql.util.ExpressionMetadata)2 ArrayList (java.util.ArrayList)2 FunctionRegistry (io.confluent.ksql.function.FunctionRegistry)1 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)1 KsqlException (io.confluent.ksql.util.KsqlException)1 Pair (io.confluent.ksql.util.Pair)1 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)1