use of io.confluent.ksql.execution.plan.StreamSelectKeyV1 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.execution.plan.StreamSelectKeyV1 in project ksql by confluentinc.
the class StreamSelectKeyBuilderV1Test method init.
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void init() {
when(buildContext.getFunctionRegistry()).thenReturn(functionRegistry);
when(buildContext.getKsqlConfig()).thenReturn(new KsqlConfig(ImmutableMap.of()));
when(kstream.filter(any())).thenReturn(filteredKStream);
when(filteredKStream.selectKey(any(KeyValueMapper.class))).thenReturn(rekeyedKstream);
when(sourceStep.build(any(), eq(planInfo))).thenReturn(new KStreamHolder<>(kstream, SOURCE_SCHEMA, mock(ExecutionKeyFactory.class)));
planBuilder = new KSPlanBuilder(buildContext, mock(SqlPredicateFactory.class), mock(AggregateParamsFactory.class), mock(StreamsFactories.class));
selectKey = new StreamSelectKeyV1(new ExecutionStepPropertiesV1(queryContext), sourceStep, KEY);
}
Aggregations