use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class SelectValueMapperIntegrationTest method shouldApplyUdfsToColumns.
@Test
public void shouldApplyUdfsToColumns() {
// Given:
final KsqlTransformer<GenericKey, GenericRow> selectTransformer = givenSelectMapperFor("SELECT col0, col1, col2, CEIL(col3) FROM test1 WHERE col0 > 100 EMIT CHANGES;");
// When:
final GenericRow row = selectTransformer.transform(NON_WINDOWED_KEY, genericRow("foo", "whatever", 6.9D, "boo", "hoo", 0, 0L, ImmutableList.of(), 1521834663L, 2L), ctx);
// Then:
assertThat(row, is(genericRow(2L, "foo", "whatever", 7.0D)));
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class KeyUtilTest method shouldConvertNonWindowedKeyToList.
@Test
public void shouldConvertNonWindowedKeyToList() {
// Given:
final GenericKey key = GenericKey.genericKey(10);
// When:
final List<?> result = KeyUtil.asList(key);
// Then:
assertThat(result, is(ImmutableList.of(10)));
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class KeyUtilTest method shouldConvertWindowedKeyToList.
@Test
public void shouldConvertWindowedKeyToList() {
// Given:
final Windowed<GenericKey> key = new Windowed<>(GenericKey.genericKey(10), new TimeWindow(1000, 2000));
// When:
final List<?> result = KeyUtil.asList(key);
// Then:
assertThat(result, is(ImmutableList.of(10, 1000L, 2000L)));
}
use of io.confluent.ksql.GenericKey in project ksql by confluentinc.
the class StreamGroupByBuilderBase method buildGrouped.
private static Grouped<GenericKey, GenericRow> buildGrouped(final Formats formats, final LogicalSchema schema, final QueryContext queryContext, final RuntimeBuildContext buildContext, final GroupedFactory groupedFactory) {
final PhysicalSchema physicalSchema = PhysicalSchema.from(schema, formats.getKeyFeatures(), formats.getValueFeatures());
final Serde<GenericKey> keySerde = buildContext.buildKeySerde(formats.getKeyFormat(), physicalSchema, queryContext);
final Serde<GenericRow> valSerde = buildContext.buildValueSerde(formats.getValueFormat(), physicalSchema, queryContext);
return groupedFactory.create(StreamsUtil.buildOpName(queryContext), keySerde, valSerde);
}
use of io.confluent.ksql.GenericKey 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));
}
Aggregations