2

I've following query on ksqldb , if I use "EMIT CHANGES" it does work, but if change it to "EMIT FINAL" it does not return any value after the window end

 CREATE TABLE sspc_3536660_v4 as select sspc,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_ds_cir_fulfillment' THEN value ELSE NULL END)AS sspc_ds_cir_fulfillment,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_ds_cir_current' THEN value ELSE NULL END )AS sspc_ds_cir_current,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_ds_cir_fulfillment_ratio' THEN value ELSE NULL END)AS sspc_ds_cir_fulfillment_ratio,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_ds_cir_demand_bytes' THEN value ELSE NULL END )AS sspc_ds_cir_demand_bytes,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_us_cir_fulfillment_ratio' THEN value ELSE NULL END)AS sspc_us_cir_fulfillment_ratio,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_ds_cir_demand_kbps' THEN value ELSE NULL END )AS sspc_ds_cir_demand_kbps,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_us_cir_demand_kbps' THEN value ELSE NULL END)AS sspc_us_cir_demand_kbps,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_us_cir_fulfillment' THEN value ELSE NULL END )AS sspc_us_cir_fulfillment,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_us_cir_demand_bytes' THEN value ELSE NULL END )AS sspc_us_cir_demand_bytes,
>LATEST_BY_OFFSET(CASE WHEN metric ='sspc_us_cir_current' THEN value ELSE NULL END)AS sspc_us_cir_current,
>count(*) as ct
>from Sspc_Usage_Stats_Transposedv3
>WINDOW TUMBLING (SIZE 5 MINUTES , GRACE PERIOD 1 MINUTES ) where  sspc=3536660
>group by sspc emit final ;

could someone give a hint ?

1 Answers1

2

EMIT FINAL is data driven, i.e., it emit results only if "stream-time" advanced beyond the window close time. "Stream-time" depends on the observed timestamps of your input record, and thus, if you stop sending input records, "stream-time" does not advance further.

Thus, if you stop sending data, the last window might never be closed, and thus you never see a result for it.

Matthias J. Sax
  • 59,682
  • 7
  • 117
  • 137
  • Can we somehow make sure the the last window of the day with be emit eventually ? It is something that has been fixed since 2021 ? – mberube.Net Jul 14 '23 at 13:15
  • The behavior is still the same. ksqlDB assumes an infinite input stream, and thus, the data of the next day would close the last window of the current day. – Matthias J. Sax Jul 14 '23 at 21:52