use of io.confluent.ksql.execution.context.QueryContext in project ksql by confluentinc.
the class MaterializationUtil method buildMaterialized.
static <K> Materialized<K, GenericRow, KeyValueStore<Bytes, byte[]>> buildMaterialized(final ExecutionStep<?> step, final LogicalSchema aggregateSchema, final Formats formats, final RuntimeBuildContext buildContext, final MaterializedFactory materializedFactory, final ExecutionKeyFactory<K> executionKeyFactory) {
final PhysicalSchema physicalAggregationSchema = PhysicalSchema.from(aggregateSchema, formats.getKeyFeatures(), formats.getValueFeatures());
final QueryContext queryContext = MaterializationUtil.materializeContext(step);
final Serde<K> keySerde = buildKeySerde(formats, physicalAggregationSchema, queryContext, executionKeyFactory);
final Serde<GenericRow> valueSerde = buildValueSerde(formats, buildContext, physicalAggregationSchema, queryContext);
return materializedFactory.create(keySerde, valueSerde, StreamsUtil.buildOpName(queryContext));
}
use of io.confluent.ksql.execution.context.QueryContext in project ksql by confluentinc.
the class SinkBuilder method build.
public static <K> void build(final LogicalSchema schema, final Formats formats, final Optional<TimestampColumn> timestampColumn, final String topicName, final KStream<K, GenericRow> stream, final ExecutionKeyFactory<K> executionKeyFactory, final QueryContext queryContext, final RuntimeBuildContext buildContext) {
final PhysicalSchema physicalSchema = PhysicalSchema.from(schema, formats.getKeyFeatures(), formats.getValueFeatures());
final Serde<K> keySerde = executionKeyFactory.buildKeySerde(formats.getKeyFormat(), physicalSchema, queryContext);
final Serde<GenericRow> valueSerde = buildContext.buildValueSerde(formats.getValueFormat(), physicalSchema, queryContext);
final Optional<TransformTimestamp<K>> tsTransformer = timestampTransformer(buildContext, queryContext, schema, timestampColumn);
final KStream<K, GenericRow> transformed = tsTransformer.map(t -> stream.transform(t, Named.as(TIMESTAMP_TRANSFORM_NAME + StreamsUtil.buildOpName(queryContext)))).orElse(stream);
transformed.to(topicName, Produced.with(keySerde, valueSerde));
}
use of io.confluent.ksql.execution.context.QueryContext 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.execution.context.QueryContext 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);
}
use of io.confluent.ksql.execution.context.QueryContext in project ksql by confluentinc.
the class StreamFlatMapBuilder method build.
public static <K> KStreamHolder<K> build(final KStreamHolder<K> stream, final StreamFlatMap<K> step, final RuntimeBuildContext buildContext) {
final List<FunctionCall> tableFunctions = step.getTableFunctions();
final LogicalSchema schema = stream.getSchema();
final Builder<TableFunctionApplier> tableFunctionAppliersBuilder = ImmutableList.builder();
final CodeGenRunner codeGenRunner = new CodeGenRunner(schema, buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
for (final FunctionCall functionCall : tableFunctions) {
final List<CompiledExpression> compiledExpressionList = new ArrayList<>(functionCall.getArguments().size());
for (final Expression expression : functionCall.getArguments()) {
final CompiledExpression compiledExpression = codeGenRunner.buildCodeGenFromParseTree(expression, "Table function");
compiledExpressionList.add(compiledExpression);
}
final KsqlTableFunction tableFunction = UdtfUtil.resolveTableFunction(buildContext.getFunctionRegistry(), functionCall, schema);
final TableFunctionApplier tableFunctionApplier = new TableFunctionApplier(tableFunction, compiledExpressionList);
tableFunctionAppliersBuilder.add(tableFunctionApplier);
}
final QueryContext queryContext = step.getProperties().getQueryContext();
final ProcessingLogger processingLogger = buildContext.getProcessingLogger(queryContext);
final ImmutableList<TableFunctionApplier> tableFunctionAppliers = tableFunctionAppliersBuilder.build();
final KStream<K, GenericRow> mapped = stream.getStream().flatTransformValues(() -> new KsTransformer<>(new KudtfFlatMapper<>(tableFunctionAppliers, processingLogger)), Named.as(StreamsUtil.buildOpName(queryContext)));
return stream.withStream(mapped, buildSchema(stream.getSchema(), step.getTableFunctions(), buildContext.getFunctionRegistry()));
}
Aggregations