use of io.confluent.ksql.model.WindowType in project ksql by confluentinc.
the class WindowInfoTest method shouldGetType.
@Test
public void shouldGetType() {
// Given:
final WindowInfo windowInfo = WindowInfo.of(SESSION, Optional.empty());
// When:
final WindowType result = windowInfo.getType();
// Then:
assertThat(result, is(SESSION));
}
use of io.confluent.ksql.model.WindowType in project ksql by confluentinc.
the class Console method formatFieldType.
private static String formatFieldType(final FieldInfo field, final Optional<WindowType> windowType, final boolean isTable) {
final FieldType possibleFieldType = field.getType().orElse(null);
if (possibleFieldType == FieldType.HEADER) {
final String headerType = field.getHeaderKey().map(k -> "(header('" + k + "'))").orElse("(headers)");
return String.format("%-16s %s", field.getSchema().toTypeString(), headerType);
}
if (possibleFieldType == FieldType.KEY) {
final String wt = windowType.map(v -> " (Window type: " + v + ")").orElse("");
final String keyType = isTable ? "(primary key)" : "(key)";
return String.format("%-16s %s%s", field.getSchema().toTypeString(), keyType, wt);
}
return field.getSchema().toTypeString();
}
use of io.confluent.ksql.model.WindowType 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());
}
};
}
use of io.confluent.ksql.model.WindowType in project ksql by confluentinc.
the class SchemaKStream method throwOnJoinKeyFormatsMismatch.
void throwOnJoinKeyFormatsMismatch(final SchemaKStream<?> right) {
final FormatInfo leftFmt = this.keyFormat.getFormatInfo();
final FormatInfo rightFmt = right.keyFormat.getFormatInfo();
if (!leftFmt.equals(rightFmt)) {
throw new IllegalArgumentException("Key format mismatch in join. " + "left: " + leftFmt + ", right: " + rightFmt);
}
final SerdeFeatures leftFeats = this.keyFormat.getFeatures();
final SerdeFeatures rightFeats = right.keyFormat.getFeatures();
if (!leftFeats.equals(rightFeats)) {
throw new IllegalArgumentException("Key format features mismatch in join. " + "left: " + leftFeats + ", right: " + rightFeats);
}
final Optional<WindowType> leftWnd = this.keyFormat.getWindowInfo().map(WindowInfo::getType);
final Optional<WindowType> rightWnd = right.keyFormat.getWindowInfo().map(WindowInfo::getType);
if (leftWnd.isPresent() != rightWnd.isPresent()) {
throw new IllegalArgumentException("Key format windowing mismatch in join. " + "left: " + leftWnd + ", right: " + rightWnd);
}
final boolean leftIsSession = leftWnd.map(type -> type == WindowType.SESSION).orElse(false);
final boolean rightIsSession = rightWnd.map(type -> type == WindowType.SESSION).orElse(false);
if (leftIsSession != rightIsSession) {
throw new IllegalArgumentException("Key format window type mismatch in join. " + "left: " + (leftIsSession ? "Session Windowed" : "Non Session Windowed") + ", right: " + (rightIsSession ? "Session Windowed" : "Non Session Windowed"));
}
}
use of io.confluent.ksql.model.WindowType in project ksql by confluentinc.
the class KsMaterialization method windowed.
// Enforced by type
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Override
public StreamsMaterializedWindowedTable windowed() {
if (!windowInfo.isPresent()) {
throw new UnsupportedOperationException("Table has non-windowed key");
}
final WindowInfo wndInfo = windowInfo.get();
final WindowType wndType = wndInfo.getType();
switch(wndType) {
case SESSION:
if (stateStore.getKsqlConfig().getBoolean(KsqlConfig.KSQL_QUERY_PULL_CONSISTENCY_OFFSET_VECTOR_ENABLED)) {
return new KsMaterializedSessionTableIQv2(stateStore);
} else {
return new KsMaterializedSessionTable(stateStore, SessionStoreCacheBypass::fetch, SessionStoreCacheBypass::fetchRange);
}
case HOPPING:
case TUMBLING:
if (stateStore.getKsqlConfig().getBoolean(KsqlConfig.KSQL_QUERY_PULL_CONSISTENCY_OFFSET_VECTOR_ENABLED)) {
return new KsMaterializedWindowTableIQv2(stateStore, wndInfo.getSize().get());
} else {
return new KsMaterializedWindowTable(stateStore, wndInfo.getSize().get(), WindowStoreCacheBypass::fetch, WindowStoreCacheBypass::fetchAll, WindowStoreCacheBypass::fetchRange);
}
default:
throw new UnsupportedOperationException("Unknown window type: " + wndInfo);
}
}
Aggregations