Search in sources :

Example 11 with PhysicalSchema

use of io.confluent.ksql.schema.ksql.PhysicalSchema in project ksql by confluentinc.

the class JoinIntTest method assertExpectedResults.

private void assertExpectedResults(final Map<GenericKey, GenericRow> expectedResults, final DataSource outputSource, final String inputTopic, final Format inputKeyFormat, final Format inputValueFormat, final long timeoutMs) {
    final PhysicalSchema schema = PhysicalSchema.from(outputSource.getSchema(), outputSource.getKsqlTopic().getKeyFormat().getFeatures(), outputSource.getKsqlTopic().getValueFormat().getFeatures());
    final Map<GenericKey, GenericRow> results = new HashMap<>();
    assertThatEventually("failed to complete join correctly", () -> {
        results.putAll(TEST_HARNESS.verifyAvailableUniqueRows(outputSource.getKafkaTopicName(), 1, FormatFactory.of(outputSource.getKsqlTopic().getKeyFormat().getFormatInfo()), FormatFactory.of(outputSource.getKsqlTopic().getValueFormat().getFormatInfo()), schema));
        final boolean success = results.equals(expectedResults);
        if (!success) {
            try {
                // The join may not be triggered fist time around due to order in which the
                // consumer pulls the records back. So we publish again to make the stream
                // trigger the join.
                TEST_HARNESS.produceRows(inputTopic, ORDER_DATA_PROVIDER, inputKeyFormat, inputValueFormat, () -> now);
            } catch (final Exception e) {
                throw new RuntimeException(e);
            }
        }
        return success;
    }, is(true), timeoutMs, TimeUnit.MILLISECONDS);
    assertThat(results, is(expectedResults));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) HashMap(java.util.HashMap) GenericKey(io.confluent.ksql.GenericKey) ZooKeeperClientException(kafka.zookeeper.ZooKeeperClientException)

Example 12 with PhysicalSchema

use of io.confluent.ksql.schema.ksql.PhysicalSchema in project ksql by confluentinc.

the class ReplaceWithSharedRuntimesIntTest method assertForSource.

private void assertForSource(final String sourceName, final String topic, final Map<GenericKey, GenericRow> expected) {
    DataSource source = ksqlContext.getMetaStore().getSource(SourceName.of(sourceName));
    PhysicalSchema resultSchema = PhysicalSchema.from(source.getSchema(), source.getKsqlTopic().getKeyFormat().getFeatures(), source.getKsqlTopic().getValueFormat().getFeatures());
    assertThat(TEST_HARNESS.verifyAvailableUniqueRows(topic, expected.size(), FormatFactory.KAFKA, FormatFactory.JSON, resultSchema), is(expected));
}
Also used : PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 13 with PhysicalSchema

use of io.confluent.ksql.schema.ksql.PhysicalSchema in project ksql by confluentinc.

the class RuntimeBuildContextTest method shouldFailWhenTackingSerdeOnSchemaMismatch.

@Test
public void shouldFailWhenTackingSerdeOnSchemaMismatch() {
    // Given:
    runtimeBuildContext.buildKeySerde(FORMAT_INFO, PHYSICAL_SCHEMA, queryContext);
    final PhysicalSchema differentSchema = PhysicalSchema.from(LogicalSchema.builder().valueColumn(ColumnName.of("f0"), SqlTypes.BOOLEAN).build(), SerdeFeatures.of(), SerdeFeatures.of());
    // When:
    assertThrows(IllegalStateException.class, () -> runtimeBuildContext.buildValueSerde(FORMAT_INFO, differentSchema, queryContext));
}
Also used : PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) Test(org.junit.Test)

Example 14 with PhysicalSchema

use of io.confluent.ksql.schema.ksql.PhysicalSchema 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));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) QueryContext(io.confluent.ksql.execution.context.QueryContext)

Example 15 with PhysicalSchema

use of io.confluent.ksql.schema.ksql.PhysicalSchema 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));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) RuntimeBuildContext(io.confluent.ksql.execution.runtime.RuntimeBuildContext) Produced(org.apache.kafka.streams.kstream.Produced) Transformer(org.apache.kafka.streams.kstream.Transformer) QueryContext(io.confluent.ksql.execution.context.QueryContext) KeyValue(org.apache.kafka.streams.KeyValue) KStream(org.apache.kafka.streams.kstream.KStream) ExecutionKeyFactory(io.confluent.ksql.execution.plan.ExecutionKeyFactory) Formats(io.confluent.ksql.execution.plan.Formats) KsqlTimestampExtractor(io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) To(org.apache.kafka.streams.processor.To) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) TimestampExtractionPolicy(io.confluent.ksql.execution.streams.timestamp.TimestampExtractionPolicy) TransformerSupplier(org.apache.kafka.streams.kstream.TransformerSupplier) GenericRow(io.confluent.ksql.GenericRow) TimestampExtractionPolicyFactory(io.confluent.ksql.execution.streams.timestamp.TimestampExtractionPolicyFactory) Serde(org.apache.kafka.common.serialization.Serde) Objects.requireNonNull(java.util.Objects.requireNonNull) Named(org.apache.kafka.streams.kstream.Named) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) Optional(java.util.Optional) RecordProcessingError(io.confluent.ksql.logging.processing.RecordProcessingError) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema)

Aggregations

PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)34 GenericRow (io.confluent.ksql.GenericRow)21 GenericKey (io.confluent.ksql.GenericKey)12 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)11 QueryContext (io.confluent.ksql.execution.context.QueryContext)9 Test (org.junit.Test)7 Formats (io.confluent.ksql.execution.plan.Formats)6 RuntimeBuildContext (io.confluent.ksql.execution.runtime.RuntimeBuildContext)6 DataSource (io.confluent.ksql.metastore.model.DataSource)6 IntegrationTest (io.confluent.common.utils.IntegrationTest)5 ProcessingLogger (io.confluent.ksql.logging.processing.ProcessingLogger)4 Serde (org.apache.kafka.common.serialization.Serde)4 Windowed (org.apache.kafka.streams.kstream.Windowed)4 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)4 KTableHolder (io.confluent.ksql.execution.plan.KTableHolder)3 SourceBuilderUtils.getPhysicalSchema (io.confluent.ksql.execution.streams.SourceBuilderUtils.getPhysicalSchema)3 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)2 KsqlSchemaAuthorizationException (io.confluent.ksql.exception.KsqlSchemaAuthorizationException)2 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)2 CodeGenRunner (io.confluent.ksql.execution.codegen.CodeGenRunner)2