Search in sources :

Example 1 with SerdeSupplier

use of io.confluent.ksql.test.serde.SerdeSupplier in project ksql by confluentinc.

the class SerdeUtil method getKeySerdeSupplier.

@SuppressWarnings("unchecked")
public static <T> SerdeSupplier<?> getKeySerdeSupplier(final KeyFormat keyFormat, final LogicalSchema schema) {
    final SerdeSupplier<T> inner = (SerdeSupplier<T>) getSerdeSupplier(FormatFactory.of(keyFormat.getFormatInfo()), schema);
    if (!keyFormat.getWindowType().isPresent()) {
        return inner;
    }
    final WindowType windowType = keyFormat.getWindowType().get();
    if (windowType == WindowType.SESSION) {
        return new SerdeSupplier<Windowed<T>>() {

            @Override
            public Serializer<Windowed<T>> getSerializer(final SchemaRegistryClient srClient, final boolean isKey) {
                final Serializer<T> serializer = inner.getSerializer(srClient, isKey);
                serializer.configure(ImmutableMap.of(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, "something"), true);
                return new SessionWindowedSerializer<>(serializer);
            }

            @Override
            public Deserializer<Windowed<T>> getDeserializer(final SchemaRegistryClient srClient, final boolean isKey) {
                final Deserializer<T> deserializer = inner.getDeserializer(srClient, isKey);
                deserializer.configure(ImmutableMap.of(), true);
                return new SessionWindowedDeserializer<>(deserializer);
            }
        };
    }
    return new SerdeSupplier<Windowed<T>>() {

        @Override
        public Serializer<Windowed<T>> getSerializer(final SchemaRegistryClient srClient, final boolean isKey) {
            final Serializer<T> serializer = inner.getSerializer(srClient, isKey);
            serializer.configure(ImmutableMap.of(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, "something"), true);
            return new TimeWindowedSerializer<>(serializer);
        }

        @SuppressWarnings("OptionalGetWithoutIsPresent")
        @Override
        public Deserializer<Windowed<T>> getDeserializer(final SchemaRegistryClient srClient, final boolean isKey) {
            final Deserializer<T> deserializer = inner.getDeserializer(srClient, isKey);
            deserializer.configure(ImmutableMap.of(), true);
            return new TimeWindowedDeserializer<>(deserializer, keyFormat.getWindowSize().get().toMillis());
        }
    };
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) StringSerdeSupplier(io.confluent.ksql.test.serde.string.StringSerdeSupplier) NoneSerdeSupplier(io.confluent.ksql.test.serde.none.NoneSerdeSupplier) ValueSpecJsonSerdeSupplier(io.confluent.ksql.test.serde.json.ValueSpecJsonSerdeSupplier) KafkaSerdeSupplier(io.confluent.ksql.test.serde.kafka.KafkaSerdeSupplier) ValueSpecAvroSerdeSupplier(io.confluent.ksql.test.serde.avro.ValueSpecAvroSerdeSupplier) SerdeSupplier(io.confluent.ksql.test.serde.SerdeSupplier) ValueSpecProtobufSerdeSupplier(io.confluent.ksql.test.serde.protobuf.ValueSpecProtobufSerdeSupplier) TimeWindowedSerializer(org.apache.kafka.streams.kstream.TimeWindowedSerializer) SessionWindowedSerializer(org.apache.kafka.streams.kstream.SessionWindowedSerializer) WindowType(io.confluent.ksql.model.WindowType) TimeWindowedDeserializer(org.apache.kafka.streams.kstream.TimeWindowedDeserializer) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) SessionWindowedDeserializer(org.apache.kafka.streams.kstream.SessionWindowedDeserializer)

Aggregations

SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 WindowType (io.confluent.ksql.model.WindowType)1 SerdeSupplier (io.confluent.ksql.test.serde.SerdeSupplier)1 ValueSpecAvroSerdeSupplier (io.confluent.ksql.test.serde.avro.ValueSpecAvroSerdeSupplier)1 ValueSpecJsonSerdeSupplier (io.confluent.ksql.test.serde.json.ValueSpecJsonSerdeSupplier)1 KafkaSerdeSupplier (io.confluent.ksql.test.serde.kafka.KafkaSerdeSupplier)1 NoneSerdeSupplier (io.confluent.ksql.test.serde.none.NoneSerdeSupplier)1 ValueSpecProtobufSerdeSupplier (io.confluent.ksql.test.serde.protobuf.ValueSpecProtobufSerdeSupplier)1 StringSerdeSupplier (io.confluent.ksql.test.serde.string.StringSerdeSupplier)1 SessionWindowedDeserializer (org.apache.kafka.streams.kstream.SessionWindowedDeserializer)1 SessionWindowedSerializer (org.apache.kafka.streams.kstream.SessionWindowedSerializer)1 TimeWindowedDeserializer (org.apache.kafka.streams.kstream.TimeWindowedDeserializer)1 TimeWindowedSerializer (org.apache.kafka.streams.kstream.TimeWindowedSerializer)1 Windowed (org.apache.kafka.streams.kstream.Windowed)1