use of org.apache.kafka.streams.kstream.SessionWindowedSerializer 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());
}
};
}
Aggregations