I want to consume KTable and materialize with optimization

Open
#2,886 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
kafka, kotlin

Research direction

Start with the KTable join and materialization paths shown in the issue, then trace how topology.optimization=all handles the automatically materialized store versus the explicit VersionedKeyValueStore. The issue does not name source files or tests; done would require a documented or tested way to select the store type without creating an unnecessary changelog topic.

Written by the indexing model from the issue text.

Description

enhancement

When I consume KTable, it is materialized as KeyValueStore automatically.

fun process() = BiConsumer<KStream<String, String>, KTable<String, String>> { input, table ->
    input.join(table) { value1, value2 ->
        Pair(value1, value2)
    }.peek { key, value -> println("$key: $value") }
}

If I set topology.optimization to all then, changelog topic is not created but reuse consuming topic as changelog topic.
Because Kafka Streams join semantics, I want to change the type of state store to VersionedKeyValueStore.
If I materialize state store manually like this, it creates changelog topic although I set topology.optimization to all.

fun process() = BiConsumer<KStream<String, String>, KTable<String, String>> { input, table ->
    val storedTable = table
        .toStream()
        .groupByKey()
        .aggregate(
            { byteArrayOf() },
            { _, value, _ -> value.toByteArray() },
            Materialized.`as`(store)
        )
    val store = Stores.persistentVersionedKeyValueStore("kafka-streams-test-store", Duration.ofDays(1))
    val stream = input.join(storedTable) { value1, value2 ->
        Pair(value1, value2)
    }.peek { key, value -> println("$key, ${value?.first}, ${value?.second?.decodeToString()") }
}

Is there any way to change the type of state store with not creating changelog topic via optimization?

related so: https://stackoverflow.com/questions/77806593/how-to-change-state-store-type-of-ktable-from-keyvaluestore-to-versionedkeyvalue

Dominant language
Java
Stars
1.1k
Forks
646
Avg merge
2d 3h
Merged PRs (30d)
8

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-cloud/spring-cloud-stream

All issues in spring-cloud/spring-cloud-stream

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.