Search in sources :

Example 21 with ProcessingLogger

use of io.confluent.ksql.logging.processing.ProcessingLogger in project ksql by confluentinc.

the class ForeignKeyTableTableJoinBuilder method build.

public static <KLeftT, KRightT> KTableHolder<KLeftT> build(final KTableHolder<KLeftT> left, final KTableHolder<KRightT> right, final ForeignKeyTableTableJoin<KLeftT, KRightT> join, final RuntimeBuildContext buildContext) {
    final LogicalSchema leftSchema = left.getSchema();
    final LogicalSchema rightSchema = right.getSchema();
    final ProcessingLogger logger = buildContext.getProcessingLogger(join.getProperties().getQueryContext());
    final ExpressionEvaluator expressionEvaluator;
    final CodeGenRunner codeGenRunner = new CodeGenRunner(leftSchema, buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
    final Optional<ColumnName> leftColumnName = join.getLeftJoinColumnName();
    final Optional<Expression> leftJoinExpression = join.getLeftJoinExpression();
    if (leftColumnName.isPresent()) {
        expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(new UnqualifiedColumnReferenceExp(leftColumnName.get()), "Left Join Expression");
    } else if (leftJoinExpression.isPresent()) {
        expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(leftJoinExpression.get(), "Left Join Expression");
    } else {
        throw new IllegalStateException("Both leftColumnName and leftJoinExpression are empty.");
    }
    final ForeignKeyJoinParams<KRightT> joinParams = ForeignKeyJoinParamsFactory.create(expressionEvaluator, leftSchema, rightSchema, logger);
    final Formats formats = join.getFormats();
    final PhysicalSchema physicalSchema = PhysicalSchema.from(joinParams.getSchema(), formats.getKeyFeatures(), formats.getValueFeatures());
    final Serde<KLeftT> keySerde = left.getExecutionKeyFactory().buildKeySerde(formats.getKeyFormat(), physicalSchema, join.getProperties().getQueryContext());
    final Serde<GenericRow> valSerde = buildContext.buildValueSerde(formats.getValueFormat(), physicalSchema, join.getProperties().getQueryContext());
    final KTable<KLeftT, GenericRow> result;
    switch(join.getJoinType()) {
        case INNER:
            result = left.getTable().join(right.getTable(), joinParams.getKeyExtractor(), joinParams.getJoiner(), Materialized.with(keySerde, valSerde));
            break;
        case LEFT:
            result = left.getTable().leftJoin(right.getTable(), joinParams.getKeyExtractor(), joinParams.getJoiner(), Materialized.with(keySerde, valSerde));
            break;
        default:
            throw new IllegalStateException("invalid join type: " + join.getJoinType());
    }
    return KTableHolder.unmaterialized(result, joinParams.getSchema(), left.getExecutionKeyFactory());
}
Also used : ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Formats(io.confluent.ksql.execution.plan.Formats) ExpressionEvaluator(io.confluent.ksql.execution.transform.ExpressionEvaluator) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) GenericRow(io.confluent.ksql.GenericRow) ColumnName(io.confluent.ksql.name.ColumnName) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) Expression(io.confluent.ksql.execution.expression.tree.Expression)

Aggregations

ProcessingLogger (io.confluent.ksql.logging.processing.ProcessingLogger)21 GenericRow (io.confluent.ksql.GenericRow)11 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)10 QueryContext (io.confluent.ksql.execution.context.QueryContext)7 CodeGenRunner (io.confluent.ksql.execution.codegen.CodeGenRunner)6 Test (org.junit.Test)6 CompiledExpression (io.confluent.ksql.execution.codegen.CompiledExpression)5 Expression (io.confluent.ksql.execution.expression.tree.Expression)5 RuntimeBuildContext (io.confluent.ksql.execution.runtime.RuntimeBuildContext)5 GenericKey (io.confluent.ksql.GenericKey)4 Stacker (io.confluent.ksql.execution.context.QueryContext.Stacker)4 Formats (io.confluent.ksql.execution.plan.Formats)4 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)4 KStreamHolder (io.confluent.ksql.execution.plan.KStreamHolder)3 KTableHolder (io.confluent.ksql.execution.plan.KTableHolder)3 KsTransformer (io.confluent.ksql.execution.streams.transform.KsTransformer)3 LoggingDeserializer (io.confluent.ksql.logging.processing.LoggingDeserializer)3 List (java.util.List)3 Serde (org.apache.kafka.common.serialization.Serde)3 WrapperSerde (org.apache.kafka.common.serialization.Serdes.WrapperSerde)3