question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Obtaining the aggregated result when a session window closes when using .suppress()

See original GitHub issue

Hello, I have a strange behaviour when using KStreams to aggregate results and SessionWindows with suppress() method to avoid getting partial aggregations.

I use:

SpringBoot 2.1.5
Spring Cloud Greenwich.SR1
Spring Cloud Stream Germantown.RELEASE
Apache Kafka 2.2.0

I have created a sample project in github, which includes the aggregation process as well as a test to be able to send a message to a topic.

return input
      .groupBy((k, v) -> "explicitKey")
      .windowedBy(SessionWindows.with(window).grace(window))
      .aggregate(
        () -> "",
        (aggKey, newValue, valueAggregate) -> String.join(" ", valueAggregate, newValue),
        (aggKey, leftList, rightList) -> String.join("", leftList, rightList),
        Materialized.<String, String, SessionStore<Bytes, byte[]>>as("InfoStore")
          .withKeySerde(Serdes.String())
          .withValueSerde(Serdes.String()))
      .suppress(Suppressed.untilWindowCloses(unbounded()))
      .toStream()
      .map((key, value) -> pair(key.key() + "--" + key.window().toString(), value));

I want to get the last aggregated result when the window closes, which seems what Suppressed.untilWindowCloses(unbounded()) does. Instead, when the window expires nothing happens, and I have to send another message for the same key to the topic in order to get the aggregated result.

I assume this is not the expected behaviour, as it seems the only way to force the aggregated result to be sent when the window closes, to no avail.

Thanks for your help.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sabbyanandancommented, Jun 18, 2019

@lukaszkrawiec: Thanks for taking the time to answer the question!

Hi, @hparkerfly. I hope the answer helps. There’s nothing in our control in SCSt to do anything more to get around the core design premise in Kafka Streams.

If you see any other anomalies in the Spring’s integration with Kafka Streams, please feel free to open a new issue.

0reactions
lukaszkrawieccommented, Jun 18, 2019

One possible option if you can identify the dummy messages would be to handle that in the aggregator code, and simply not add them to the aggregate that you are generating.

Another would be to create a state store on top of a KTable, and query it using an InteractiveQueryService. You can find an example on how to do that here: https://github.com/spring-cloud/spring-cloud-stream-samples/tree/master/kafka-streams-samples/kafka-streams-interactive-query-advanced

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kafka Stream Suppress session-windowed-aggregation
As per my knowledge, suppress() works only with Time Based Windows & it does not work with Session Based Windows.
Read more >
Stream Aggregation In Kafka - Narayan Kumar - Medium
In order to aggregate the stream we need do two steps operations. Group the stream — groupBy(k,v) (if Key exist in stream) or...
Read more >
Kafka Streams Stateful Ingestion with Processor API
The output of reduce() is a KTable object and suppress() ensures aggregation results are forwarded only after the window has expired, ...
Read more >
KIP-450: Sliding Window Aggregations in the DSL
This feature can be suppressed through suppression, which allows users to ignore all results except for the final one, only emitting after the...
Read more >
Time and Windows - ksqlDB Documentation
When using windows in your SQL queries, aggregate functions are applied only to the records that occur within a specific time window.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found