Search in sources :

Example 1 with WindowType

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

Example 2 with WindowType

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();
}
Also used : Arrays(java.util.Arrays) Builder(io.confluent.ksql.cli.console.table.Table.Builder) StreamsList(io.confluent.ksql.rest.entity.StreamsList) PropertiesListTableBuilder(io.confluent.ksql.cli.console.table.builder.PropertiesListTableBuilder) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) OnOff(io.confluent.ksql.cli.console.CliConfig.OnOff) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) StringUtils(org.apache.commons.lang3.StringUtils) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) Map(java.util.Map) WindowType(io.confluent.ksql.model.WindowType) TablesListTableBuilder(io.confluent.ksql.cli.console.table.builder.TablesListTableBuilder) Path(java.nio.file.Path) PrintWriter(java.io.PrintWriter) TableBuilder(io.confluent.ksql.cli.console.table.builder.TableBuilder) TypeList(io.confluent.ksql.rest.entity.TypeList) ListVariablesTableBuilder(io.confluent.ksql.cli.console.table.builder.ListVariablesTableBuilder) StatusClosable(io.confluent.ksql.cli.console.KsqlTerminal.StatusClosable) Handler1(io.confluent.ksql.util.HandlerMaps.Handler1) ArgumentInfo(io.confluent.ksql.rest.entity.ArgumentInfo) ApiJsonMapper(io.confluent.ksql.rest.ApiJsonMapper) ZoneId(java.time.ZoneId) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Stream(java.util.stream.Stream) TopicDescription(io.confluent.ksql.rest.entity.TopicDescription) KsqlException(io.confluent.ksql.util.KsqlException) TerminateQueryTableBuilder(io.confluent.ksql.cli.console.table.builder.TerminateQueryTableBuilder) DropConnectorEntity(io.confluent.ksql.rest.entity.DropConnectorEntity) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) TopicDescriptionTableBuilder(io.confluent.ksql.cli.console.table.builder.TopicDescriptionTableBuilder) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) Supplier(java.util.function.Supplier) CmdLineUtil.splitByUnquotedWhitespace(io.confluent.ksql.util.CmdLineUtil.splitByUnquotedWhitespace) DropConnectorTableBuilder(io.confluent.ksql.cli.console.table.builder.DropConnectorTableBuilder) StringTokenizer(java.util.StringTokenizer) TypeListTableBuilder(io.confluent.ksql.cli.console.table.builder.TypeListTableBuilder) CliSpecificCommand(io.confluent.ksql.cli.console.cmd.CliSpecificCommand) IOException(java.io.IOException) File(java.io.File) Paths(java.nio.file.Paths) Signal(org.jline.terminal.Terminal.Signal) HandlerMaps(io.confluent.ksql.util.HandlerMaps) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) QueryOffsetSummary(io.confluent.ksql.rest.entity.QueryOffsetSummary) LoggerFactory(org.slf4j.LoggerFactory) Header(io.confluent.ksql.rest.entity.StreamedRow.Header) WarningEntityTableBuilder(io.confluent.ksql.cli.console.table.builder.WarningEntityTableBuilder) QueryTopicOffsetSummary(io.confluent.ksql.rest.entity.QueryTopicOffsetSummary) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) KafkaTopicsListExtended(io.confluent.ksql.rest.entity.KafkaTopicsListExtended) DataRow(io.confluent.ksql.rest.entity.StreamedRow.DataRow) CommandStatusTableBuilder(io.confluent.ksql.cli.console.table.builder.CommandStatusTableBuilder) ExecutionPlan(io.confluent.ksql.rest.entity.ExecutionPlan) StreamsListTableBuilder(io.confluent.ksql.cli.console.table.builder.StreamsListTableBuilder) Table(io.confluent.ksql.cli.console.table.Table) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ClassHandlerMap1(io.confluent.ksql.util.HandlerMaps.ClassHandlerMap1) QueriesTableBuilder(io.confluent.ksql.cli.console.table.builder.QueriesTableBuilder) ErrorEntityTableBuilder(io.confluent.ksql.cli.console.table.builder.ErrorEntityTableBuilder) FieldType(io.confluent.ksql.rest.entity.FieldInfo.FieldType) Streams(com.google.common.collect.Streams) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) List(java.util.List) CreateConnectorEntity(io.confluent.ksql.rest.entity.CreateConnectorEntity) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) Entry(java.util.Map.Entry) ConnectorInfoTableBuilder(io.confluent.ksql.cli.console.table.builder.ConnectorInfoTableBuilder) Optional(java.util.Optional) ExecutionPlanTableBuilder(io.confluent.ksql.cli.console.table.builder.ExecutionPlanTableBuilder) WarningEntity(io.confluent.ksql.rest.entity.WarningEntity) HistoryEntry(io.confluent.ksql.cli.console.KsqlTerminal.HistoryEntry) TerminateQueryEntity(io.confluent.ksql.rest.entity.TerminateQueryEntity) ConnectorPluginsListTableBuilder(io.confluent.ksql.cli.console.table.builder.ConnectorPluginsListTableBuilder) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) QueryError(io.confluent.ksql.query.QueryError) SignalHandler(org.jline.terminal.Terminal.SignalHandler) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ImmutableList(com.google.common.collect.ImmutableList) Charset(java.nio.charset.Charset) ObjectUtils(org.apache.commons.lang3.ObjectUtils) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KafkaTopicsListTableBuilder(io.confluent.ksql.cli.console.table.builder.KafkaTopicsListTableBuilder) Queries(io.confluent.ksql.rest.entity.Queries) TablesList(io.confluent.ksql.rest.entity.TablesList) VariablesList(io.confluent.ksql.rest.entity.VariablesList) CmdLineUtil(io.confluent.ksql.util.CmdLineUtil) TabularRow(io.confluent.ksql.util.TabularRow) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Maps(com.google.common.collect.Maps) ConfigException(org.apache.kafka.common.config.ConfigException) ConnectorListTableBuilder(io.confluent.ksql.cli.console.table.builder.ConnectorListTableBuilder) FunctionNameListTableBuilder(io.confluent.ksql.cli.console.table.builder.FunctionNameListTableBuilder) Closeable(java.io.Closeable) DateTimeFormatter(java.time.format.DateTimeFormatter) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) Comparator(java.util.Comparator) Collections(java.util.Collections) FieldType(io.confluent.ksql.rest.entity.FieldInfo.FieldType)

Example 3 with WindowType

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());
        }
    };
}
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)

Example 4 with WindowType

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"));
    }
}
Also used : StatementRewriteForMagicPseudoTimestamp(io.confluent.ksql.engine.rewrite.StatementRewriteForMagicPseudoTimestamp) ColumnName(io.confluent.ksql.name.ColumnName) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) StreamFilter(io.confluent.ksql.execution.plan.StreamFilter) KeyFormat(io.confluent.ksql.serde.KeyFormat) QueryContext(io.confluent.ksql.execution.context.QueryContext) JoinType(io.confluent.ksql.execution.plan.JoinType) SerdeFeaturesFactory(io.confluent.ksql.serde.SerdeFeaturesFactory) Formats(io.confluent.ksql.execution.plan.Formats) StreamGroupByKey(io.confluent.ksql.execution.plan.StreamGroupByKey) StepSchemaResolver(io.confluent.ksql.execution.streams.StepSchemaResolver) WindowInfo(io.confluent.ksql.serde.WindowInfo) NoneFormat(io.confluent.ksql.serde.none.NoneFormat) StreamSelect(io.confluent.ksql.execution.plan.StreamSelect) Objects.requireNonNull(java.util.Objects.requireNonNull) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) WindowType(io.confluent.ksql.model.WindowType) Repartitioning(io.confluent.ksql.util.Repartitioning) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ExecutionStepFactory(io.confluent.ksql.execution.streams.ExecutionStepFactory) StreamTableJoin(io.confluent.ksql.execution.plan.StreamTableJoin) ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) PlanBuildContext(io.confluent.ksql.planner.plan.PlanBuildContext) Expression(io.confluent.ksql.execution.expression.tree.Expression) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) KsqlConfig(io.confluent.ksql.util.KsqlConfig) InternalFormats(io.confluent.ksql.serde.InternalFormats) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) Objects(java.util.Objects) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) List(java.util.List) StreamStreamJoin(io.confluent.ksql.execution.plan.StreamStreamJoin) StreamSink(io.confluent.ksql.execution.plan.StreamSink) Stacker(io.confluent.ksql.execution.context.QueryContext.Stacker) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) StreamFlatMap(io.confluent.ksql.execution.plan.StreamFlatMap) FormatInfo(io.confluent.ksql.serde.FormatInfo) StreamGroupBy(io.confluent.ksql.execution.plan.StreamGroupBy) FormatInfo(io.confluent.ksql.serde.FormatInfo) WindowType(io.confluent.ksql.model.WindowType) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) WindowInfo(io.confluent.ksql.serde.WindowInfo)

Example 5 with WindowType

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);
    }
}
Also used : WindowType(io.confluent.ksql.model.WindowType) WindowInfo(io.confluent.ksql.serde.WindowInfo)

Aggregations

WindowType (io.confluent.ksql.model.WindowType)5 WindowInfo (io.confluent.ksql.serde.WindowInfo)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 Streams (com.google.common.collect.Streams)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 OnOff (io.confluent.ksql.cli.console.CliConfig.OnOff)1 HistoryEntry (io.confluent.ksql.cli.console.KsqlTerminal.HistoryEntry)1 StatusClosable (io.confluent.ksql.cli.console.KsqlTerminal.StatusClosable)1 CliSpecificCommand (io.confluent.ksql.cli.console.cmd.CliSpecificCommand)1 Table (io.confluent.ksql.cli.console.table.Table)1 Builder (io.confluent.ksql.cli.console.table.Table.Builder)1 CommandStatusTableBuilder (io.confluent.ksql.cli.console.table.builder.CommandStatusTableBuilder)1 ConnectorInfoTableBuilder (io.confluent.ksql.cli.console.table.builder.ConnectorInfoTableBuilder)1 ConnectorListTableBuilder (io.confluent.ksql.cli.console.table.builder.ConnectorListTableBuilder)1 ConnectorPluginsListTableBuilder (io.confluent.ksql.cli.console.table.builder.ConnectorPluginsListTableBuilder)1 DropConnectorTableBuilder (io.confluent.ksql.cli.console.table.builder.DropConnectorTableBuilder)1 ErrorEntityTableBuilder (io.confluent.ksql.cli.console.table.builder.ErrorEntityTableBuilder)1