Ksqldb EMIT FINAL

create table Prite_Dup_Table as SELECT 
AFTER -> ID as ID,
LATEST_BY_OFFSET(AFTER -> FIRST_NAME) as FIRST_NAME,
LATEST_BY_OFFSET(AFTER -> LAST_NAME) as LAST_NAME,
SUM(AFTER -> AMOUNT) as AMOUNT
FROM Prite_Dup
WINDOW TUMBLING (SIZE 1 SECONDS)
GROUP BY AFTER -> ID EMIT FINAL;

after use EMIT FINAL and insert duplicate data in 1 seconds but no output on SELECT command and topic
Why EMIT FINAL no result on topic

This should work. What does the DDL for Prite_Dup look like? Are you using the record timestamps (default) or event time (more here on time semantics)?

You might compare to the following EMIT FINAL example (based on this tumbling windows tutorial) to see EMIT FINAL working as expected and compare it to your setup. What’s different about them?

Create raw event stream:

CREATE STREAM movieratings (title VARCHAR, release_year INT, rating DOUBLE)
    WITH (kafka_topic='movieratings',
          partitions=1,
          value_format='avro');

Kick off windowed aggregation EMIT FINAL query:

SELECT title,
       COUNT(*) AS rating_count,
       WINDOWSTART AS window_start,
       WINDOWEND AS window_end, LATEST_BY_OFFSET(rating)
FROM movieratings
WINDOW TUMBLING (SIZE 1 SECONDS)
GROUP BY title
EMIT FINAL;

Repeatedly run the following insert statement to insert duplicate data with different record timestamps:

INSERT INTO movieratings (title, release_year, rating) VALUES ('Die Hard', 1998, 6.7);

You should see only one row emitted per window, and it should get emitted when the window closes (e.g., insert one row, count 2 seconds, and then insert another – at this point the first window closes and you’ll see the row emitted).

1 Like

Hi dtroiano

I try to use your scenario command

  1. Create raw stream
CREATE STREAM movieratings (title VARCHAR, release_year INT, rating DOUBLE)
    WITH (kafka_topic='movieratings',
          partitions=1,
          value_format='avro');
  1. exec select window emit final
SELECT title,
       COUNT(*) AS rating_count,
       WINDOWSTART AS window_start,
       WINDOWEND AS window_end, LATEST_BY_OFFSET(rating)
FROM movieratings
WINDOW TUMBLING (SIZE 1 SECONDS)
GROUP BY title
EMIT FINAL;
  1. select raw stream for compare
select * from movieratings emit changes;
  1. try to insert into

round 1

INSERT INTO movieratings (title, release_year, rating) VALUES ('Die Hard', 1998, 6.7);

round 2

INSERT INTO movieratings (title, release_year, rating) VALUES ('Die Hard', 1998, 6.7);
INSERT INTO movieratings (title, release_year, rating) VALUES ('Die Hard', 1998, 6.7);

result from

select * from movieratings emit changes;

have 3 row because we insert into 3 row in 2 round

SELECT title,
       COUNT(*) AS rating_count,
       WINDOWSTART AS window_start,
       WINDOWEND AS window_end, LATEST_BY_OFFSET(rating)
FROM movieratings
WINDOW TUMBLING (SIZE 1 SECONDS)
GROUP BY title
EMIT FINAL;

from EMIT FINAL no result of both round
Why no output on emit final?

I use ksqlDB 7.5.0

This topic was automatically closed after 30 days. New replies are no longer allowed.