confluentinc / ksql

The database purpose-built for stream processing applications.
https://ksqldb.io
Other
127 stars 1.04k forks source link

MIN and MAX aggregate functions are not supported in Table query #1726

Open vasiliybondarenko opened 6 years ago

vasiliybondarenko commented 6 years ago

Running the query like CREATE TABLE t1 AS SELECT Id, MIN(updatedAt) as updated from d1 WHERE ... GROUP BY Id where updatedAt's type is BIGINT results in error

The aggregation function(s) (MIN) cannot be applied to a table.

yashbmewada commented 6 years ago

Even I have faced the same with MAX query over a windowed table. Ended up Writing a custom processor Kafka streams app instead.

sjs7007 commented 6 years ago

I face the same issue as well.

hjafarpour commented 6 years ago

@vasiliybondarenko , @sjs7007 Unfortunately we cannot easily compute the Min/Max values for tables in KafkaStreams. Note that the queries that we have are continuous queries and we need to keep the results up to date. For a table when we compute a min value if we delete that value we will receive a tombstone message indicating the deletion. In order to update the new min value we have to remember the second min value which is not trivial. Handling deletes are easier for count and sum aggregates and we have those for tables.

timjenkel commented 2 years ago

I found a workaround for this, though it might not be the most efficient way: SELECT ARRAY_MIN(COLLECT_LIST(value)) ...

alphonsejayapal commented 1 year ago

I found a workaround for this, though it might not be the most efficient way: SELECT ARRAY_MIN(COLLECT_LIST(value)) ...

Thank you very much