0

I am following this link to query a materialized view and is expecting a group by to return only one row per key but it is not (sensor-1 appears twice in below query):

ksql> SELECT sensor,                                                                                                                                
>           LATEST_BY_OFFSET(area) AS area,                                                                                                         
>           LATEST_BY_OFFSET(reading) AS last                                                                                                       
>    FROM readings                                                                                                                                  
>    GROUP BY sensor                                                                                                                                
>    EMIT CHANGES;                                                                                                                                  
+------------------------------------------------+------------------------------------------------+------------------------------------------------+
|SENSOR                                          |AREA                                            |LAST                                            |
+------------------------------------------------+------------------------------------------------+------------------------------------------------+
|sensor-1                                        |wheel                                           |45                                              |
|sensor-2                                        |motor                                           |41                                              |
|sensor-1                                        |wheel                                           |92                                              |

and same result with the view materialized:

CREATE TABLE latest_readings AS
    SELECT sensor,
           LATEST_BY_OFFSET(area) AS area,
           LATEST_BY_OFFSET(reading) AS last
    FROM readings
    GROUP BY sensor
    EMIT CHANGES;

This seems to be different from robin-moffatt answer as in Is it possible to get the latest value for a message key from kafka messages

Did I miss something?

rmcv
  • 1,956
  • 1
  • 9
  • 8

1 Answers1

0

It is my understanding that the emit changes will push out updates as they occur, therefore, when there is an update to the set for a given key a change will be emitted for that key.

David
  • 19,389
  • 12
  • 63
  • 87