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);
}
Aggregations