Search in sources :

Example 56 with GenericKey

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)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 57 with GenericKey

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)));
}
Also used : GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 58 with GenericKey

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)));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) GenericKey(io.confluent.ksql.GenericKey) TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Example 59 with GenericKey

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);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) GenericKey(io.confluent.ksql.GenericKey)

Example 60 with GenericKey

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));
}
Also used : KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) StreamSelectKeyV1(io.confluent.ksql.execution.plan.StreamSelectKeyV1) RuntimeBuildContext(io.confluent.ksql.execution.runtime.RuntimeBuildContext) GenericRow(io.confluent.ksql.GenericRow) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) GenericKey(io.confluent.ksql.GenericKey) KStream(org.apache.kafka.streams.kstream.KStream) ExecutionKeyFactory(io.confluent.ksql.execution.plan.ExecutionKeyFactory) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Function(java.util.function.Function) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey)

Aggregations

GenericKey (io.confluent.ksql.GenericKey)147 GenericRow (io.confluent.ksql.GenericRow)100 Test (org.junit.Test)93 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)24 Windowed (org.apache.kafka.streams.kstream.Windowed)20 WindowedRow (io.confluent.ksql.execution.streams.materialization.WindowedRow)14 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)14 Materialized (org.apache.kafka.streams.kstream.Materialized)13 ValueAndTimestamp (org.apache.kafka.streams.state.ValueAndTimestamp)13 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)12 MaterializationException (io.confluent.ksql.execution.streams.materialization.MaterializationException)9 IntegrationTest (io.confluent.common.utils.IntegrationTest)8 Materialization (io.confluent.ksql.execution.streams.materialization.Materialization)8 Row (io.confluent.ksql.execution.streams.materialization.Row)8 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)8 TimeWindow (org.apache.kafka.streams.kstream.internals.TimeWindow)8 IntegrationTest (org.apache.kafka.test.IntegrationTest)8 InOrder (org.mockito.InOrder)8 MaterializedTable (io.confluent.ksql.execution.streams.materialization.MaterializedTable)7 Objects (java.util.Objects)7