Click to copy

• Reviewed for ksqlDB 0.29

How to Reduce or Combine Elements in Array in ksqlDB

To aggregate the values in an array into a single value by applying a custom function, you can use REDUCE as follows:

SELECT
  REDUCE(hourly_measurements, 0, (s, x) => MAX(s, x)) AS max_temperature
FROM
  daily_temperature;

The stream in the example was created using the following statement, where hourly_measurements has a number series of measurements taken at each particular date.

CREATE STREAM daily_temperature (
  hourly_measurements ARRAY<DOUBLE>,
  ...
) WITH (...)
Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like