use of io.confluent.ksql.logging.processing.ProcessingLogger in project ksql by confluentinc.
the class GenericSerdeFactory method wrapInLoggingSerde.
// Part of injected API
@SuppressWarnings("MethodMayBeStatic")
<T> Serde<T> wrapInLoggingSerde(final Serde<T> formatSerde, final String loggerNamePrefix, final ProcessingLogContext processingLogContext) {
final ProcessingLogger serializerProcessingLogger = processingLogContext.getLoggerFactory().getLogger(join(loggerNamePrefix, SERIALIZER_LOGGER_NAME));
final ProcessingLogger deserializerProcessingLogger = processingLogContext.getLoggerFactory().getLogger(join(loggerNamePrefix, DESERIALIZER_LOGGER_NAME));
return Serdes.serdeFrom(new LoggingSerializer<>(formatSerde.serializer(), serializerProcessingLogger), new LoggingDeserializer<>(formatSerde.deserializer(), deserializerProcessingLogger));
}
use of io.confluent.ksql.logging.processing.ProcessingLogger 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);
}
use of io.confluent.ksql.logging.processing.ProcessingLogger in project ksql by confluentinc.
the class StreamSelectBuilder method build.
public static <K> KStreamHolder<K> build(final KStreamHolder<K> stream, final StreamSelect<K> step, final RuntimeBuildContext buildContext) {
final QueryContext queryContext = step.getProperties().getQueryContext();
final LogicalSchema sourceSchema = stream.getSchema();
final Selection<K> selection = Selection.of(sourceSchema, step.getKeyColumnNames(), step.getSelectExpressions(), buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
final SelectValueMapper<K> selectMapper = selection.getMapper();
final ProcessingLogger logger = buildContext.getProcessingLogger(queryContext);
final Named selectName = Named.as(StreamsUtil.buildOpName(queryContext));
return stream.withStream(stream.getStream().transformValues(() -> new KsTransformer<>(selectMapper.getTransformer(logger)), selectName), selection.getSchema());
}
use of io.confluent.ksql.logging.processing.ProcessingLogger in project ksql by confluentinc.
the class StreamSelectKeyBuilderV1 method build.
public static KStreamHolder<GenericKey> build(final KStreamHolder<?> stream, final StreamSelectKeyV1 selectKey, final RuntimeBuildContext buildContext) {
final LogicalSchema sourceSchema = stream.getSchema();
final CompiledExpression expression = buildExpressionEvaluator(selectKey, buildContext, sourceSchema);
final ProcessingLogger processingLogger = buildContext.getProcessingLogger(selectKey.getProperties().getQueryContext());
final String errorMsg = "Error extracting new key using expression " + selectKey.getKeyExpression();
final Function<GenericRow, Object> evaluator = val -> expression.evaluate(val, null, processingLogger, () -> errorMsg);
final LogicalSchema resultSchema = new StepSchemaResolver(buildContext.getKsqlConfig(), buildContext.getFunctionRegistry()).resolve(selectKey, sourceSchema);
final KStream<?, GenericRow> kstream = stream.getStream();
final KStream<GenericKey, GenericRow> rekeyed = kstream.filter((key, val) -> val != null && evaluator.apply(val) != null).selectKey((key, val) -> GenericKey.genericKey(evaluator.apply(val)));
return new KStreamHolder<>(rekeyed, resultSchema, ExecutionKeyFactory.unwindowed(buildContext));
}
use of io.confluent.ksql.logging.processing.ProcessingLogger in project ksql by confluentinc.
the class TableSelectKeyBuilder method build.
@VisibleForTesting
static <K> KTableHolder<K> build(final KTableHolder<K> table, final TableSelectKey<K> selectKey, final RuntimeBuildContext buildContext, final MaterializedFactory materializedFactory, final PartitionByParamsBuilder paramsBuilder) {
final LogicalSchema sourceSchema = table.getSchema();
final QueryContext queryContext = selectKey.getProperties().getQueryContext();
final ProcessingLogger logger = buildContext.getProcessingLogger(queryContext);
final PartitionByParams<K> params = paramsBuilder.build(sourceSchema, table.getExecutionKeyFactory(), selectKey.getKeyExpressions(), buildContext.getKsqlConfig(), buildContext.getFunctionRegistry(), logger);
final Mapper<K> mapper = params.getMapper();
final KTable<K, GenericRow> kTable = table.getTable();
final Materialized<K, GenericRow, KeyValueStore<Bytes, byte[]>> materialized = MaterializationUtil.buildMaterialized(selectKey, params.getSchema(), selectKey.getInternalFormats(), buildContext, materializedFactory, table.getExecutionKeyFactory());
final KTable<K, GenericRow> reKeyed = kTable.toStream().map(mapper, Named.as(queryContext.formatContext() + "-SelectKey-Mapper")).toTable(Named.as(queryContext.formatContext() + "-SelectKey"), materialized);
final MaterializationInfo.Builder materializationBuilder = MaterializationInfo.builder(StreamsUtil.buildOpName(MaterializationUtil.materializeContext(selectKey)), params.getSchema());
return KTableHolder.materialized(reKeyed, params.getSchema(), table.getExecutionKeyFactory().withQueryBuilder(buildContext), materializationBuilder);
}
Aggregations