Search in sources :

Example 1 with Mapper

use of io.confluent.ksql.execution.streams.PartitionByParams.Mapper in project ksql by confluentinc.

the class PartitionByParamsFactory method build.

public static <K> PartitionByParams<K> build(final LogicalSchema sourceSchema, final ExecutionKeyFactory<K> serdeFactory, final List<Expression> partitionBys, final KsqlConfig ksqlConfig, final FunctionRegistry functionRegistry, final ProcessingLogger logger) {
    final List<PartitionByColumn> partitionByCols = getPartitionByColumnName(sourceSchema, partitionBys);
    final LogicalSchema resultSchema = buildSchema(sourceSchema, partitionBys, functionRegistry, partitionByCols);
    final Mapper<K> mapper;
    if (isPartitionByNull(partitionBys)) {
        // In case of PARTITION BY NULL, it is sufficient to set the new key to null as the old key
        // is already present in the current value
        mapper = (k, v) -> new KeyValue<>(null, v);
    } else {
        final List<PartitionByExpressionEvaluator> evaluators = partitionBys.stream().map(pby -> {
            final Set<? extends ColumnReferenceExp> sourceColsInPartitionBy = ColumnExtractor.extractColumns(pby);
            final boolean partitionByInvolvesKeyColsOnly = sourceColsInPartitionBy.stream().map(ColumnReferenceExp::getColumnName).allMatch(sourceSchema::isKeyColumn);
            return buildExpressionEvaluator(sourceSchema, pby, ksqlConfig, functionRegistry, logger, partitionByInvolvesKeyColsOnly);
        }).collect(Collectors.toList());
        mapper = buildMapper(partitionByCols, evaluators, serdeFactory);
    }
    return new PartitionByParams<>(resultSchema, mapper);
}
Also used : ColumnExtractor(io.confluent.ksql.execution.util.ColumnExtractor) ColumnName(io.confluent.ksql.name.ColumnName) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) KeyUtil(io.confluent.ksql.execution.util.KeyUtil) Supplier(java.util.function.Supplier) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) Mapper(io.confluent.ksql.execution.streams.PartitionByParams.Mapper) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) ColumnNames(io.confluent.ksql.schema.ksql.ColumnNames) Expression(io.confluent.ksql.execution.expression.tree.Expression) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) KeyValue(org.apache.kafka.streams.KeyValue) Set(java.util.Set) KsqlConfig(io.confluent.ksql.util.KsqlConfig) ExecutionKeyFactory(io.confluent.ksql.execution.plan.ExecutionKeyFactory) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) Objects(java.util.Objects) List(java.util.List) ColumnAliasGenerator(io.confluent.ksql.schema.ksql.ColumnAliasGenerator) Stream(java.util.stream.Stream) GenericRow(io.confluent.ksql.GenericRow) KsqlException(io.confluent.ksql.util.KsqlException) GenericKey(io.confluent.ksql.GenericKey) Column(io.confluent.ksql.schema.ksql.Column) ColumnReferenceExp(io.confluent.ksql.execution.expression.tree.ColumnReferenceExp) Set(java.util.Set) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Aggregations

GenericKey (io.confluent.ksql.GenericKey)1 GenericRow (io.confluent.ksql.GenericRow)1 CodeGenRunner (io.confluent.ksql.execution.codegen.CodeGenRunner)1 CompiledExpression (io.confluent.ksql.execution.codegen.CompiledExpression)1 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 NullLiteral (io.confluent.ksql.execution.expression.tree.NullLiteral)1 ExecutionKeyFactory (io.confluent.ksql.execution.plan.ExecutionKeyFactory)1 Mapper (io.confluent.ksql.execution.streams.PartitionByParams.Mapper)1 ColumnExtractor (io.confluent.ksql.execution.util.ColumnExtractor)1 ExpressionTypeManager (io.confluent.ksql.execution.util.ExpressionTypeManager)1 KeyUtil (io.confluent.ksql.execution.util.KeyUtil)1 FunctionRegistry (io.confluent.ksql.function.FunctionRegistry)1 ProcessingLogger (io.confluent.ksql.logging.processing.ProcessingLogger)1 ColumnName (io.confluent.ksql.name.ColumnName)1 Column (io.confluent.ksql.schema.ksql.Column)1 ColumnAliasGenerator (io.confluent.ksql.schema.ksql.ColumnAliasGenerator)1 ColumnNames (io.confluent.ksql.schema.ksql.ColumnNames)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 Builder (io.confluent.ksql.schema.ksql.LogicalSchema.Builder)1