CREATE TABLE numbers_input_df_func ( "number" INT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(number), TIME INDEX(ts) ); -- call `sum(abs(number))` where `abs` is DataFusion Function and `sum` is flow function CREATE FLOW test_numbers_df_func SINK TO out_num_cnt_df_func AS SELECT sum(abs(number)), date_bin(INTERVAL '1 second', ts, '2021-07-01 00:00:00') as time_window FROM numbers_input_df_func GROUP BY time_window; INSERT INTO numbers_input_df_func VALUES (-20, "2021-07-01 00:00:00.200"), (22, "2021-07-01 00:00:00.600"); -- flush flow to make sure that table is created and data is inserted -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('test_numbers_df_func'); -- note that this quote-unquote column is a column-name, **not** a aggregation expr, generated by datafusion SELECT "sum(abs(numbers_input_df_func.number))", time_window FROM out_num_cnt_df_func; INSERT INTO numbers_input_df_func VALUES (23,"2021-07-01 00:00:01.000"), (-24,"2021-07-01 00:00:01.500"); -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('test_numbers_df_func'); -- note that this quote-unquote column is a column-name, **not** a aggregation expr, generated by datafusion SELECT "sum(abs(numbers_input_df_func.number))", time_window FROM out_num_cnt_df_func; DROP FLOW test_numbers_df_func; DROP TABLE numbers_input_df_func; DROP TABLE out_num_cnt_df_func; CREATE TABLE numbers_input_df_func ( "number" INT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(number), TIME INDEX(ts) ); -- call `abs(sum(number))`to make sure that calling `abs` function(impl by datafusion) on `sum` function(impl by flow) is working CREATE FLOW test_numbers_df_func SINK TO out_num_cnt_df_func AS SELECT abs(sum(number)), date_bin(INTERVAL '1 second', ts, '2021-07-01 00:00:00') as time_window FROM numbers_input_df_func GROUP BY time_window; INSERT INTO numbers_input_df_func VALUES (-20, "2021-07-01 00:00:00.200"), (22, "2021-07-01 00:00:00.600"); -- flush flow to make sure that table is created and data is inserted -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('test_numbers_df_func'); SELECT "abs(sum(numbers_input_df_func.number))", time_window FROM out_num_cnt_df_func; INSERT INTO numbers_input_df_func VALUES (23,"2021-07-01 00:00:01.000"), (-24,"2021-07-01 00:00:01.500"); -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('test_numbers_df_func'); SELECT "abs(sum(numbers_input_df_func.number))", time_window FROM out_num_cnt_df_func; DROP FLOW test_numbers_df_func; DROP TABLE numbers_input_df_func; DROP TABLE out_num_cnt_df_func; -- test date_bin CREATE TABLE numbers_input_df_func ( "number" INT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(number), TIME INDEX(ts) ); CREATE FLOW test_numbers_df_func SINK TO out_num_cnt_df_func AS SELECT max(number) - min(number) as maxmin, date_bin(INTERVAL '1 second', ts, '2021-07-01 00:00:00'::Timestamp) as time_window FROM numbers_input_df_func GROUP BY time_window; INSERT INTO numbers_input_df_func VALUES (20, "2021-07-01 00:00:00.200"), (22, "2021-07-01 00:00:00.600"); -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('test_numbers_df_func'); SELECT maxmin, time_window FROM out_num_cnt_df_func; INSERT INTO numbers_input_df_func VALUES (23,"2021-07-01 00:00:01.000"), (24,"2021-07-01 00:00:01.500"); -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('test_numbers_df_func'); SELECT maxmin, time_window FROM out_num_cnt_df_func; DROP FLOW test_numbers_df_func; DROP TABLE numbers_input_df_func; DROP TABLE out_num_cnt_df_func; CREATE TABLE case_time_input ( "EventTime" TIMESTAMP TIME INDEX, "eventtime" TIMESTAMP, v BIGINT ); CREATE FLOW case_time_flow SINK TO case_time_sink AS SELECT date_bin(INTERVAL '1 minute', "EventTime", '2024-01-01') AS bucket, sum(v) AS total FROM case_time_input GROUP BY bucket; -- Filtering on the lowercase column would drop the second row and the entire second bucket. INSERT INTO case_time_input VALUES ('2024-01-01 10:00:05', '2024-01-01 10:00:09', 10), ('2024-01-01 10:00:15', '2024-01-01 10:07:15', 20), ('2024-01-01 10:01:05', '2024-01-01 10:08:05', 40); -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('case_time_flow'); SELECT date_bin(INTERVAL '1 minute', "EventTime", '2024-01-01') AS bucket, sum(v) AS total FROM case_time_input GROUP BY bucket ORDER BY bucket; SELECT bucket, total FROM case_time_sink ORDER BY bucket; DROP FLOW case_time_flow; DROP TABLE case_time_input; DROP TABLE case_time_sink; CREATE TABLE dotted_time_input ("event.time" TIMESTAMP TIME INDEX, v BIGINT); CREATE FLOW dotted_time_flow SINK TO dotted_time_sink AS SELECT date_bin(INTERVAL '1 minute', "event.time", '2024-01-01') AS bucket, sum(v) AS total FROM dotted_time_input GROUP BY bucket; INSERT INTO dotted_time_input VALUES ('2024-01-01 10:00:05', 10); -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('dotted_time_flow'); SELECT bucket, total FROM dotted_time_sink ORDER BY bucket; DROP FLOW dotted_time_flow; DROP TABLE dotted_time_input; DROP TABLE dotted_time_sink; -- test date_trunc CREATE TABLE numbers_input_df_func ( "number" INT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(number), TIME INDEX(ts) ); CREATE FLOW test_numbers_df_func SINK TO out_num_cnt AS SELECT date_trunc('second', ts) as time_window, sum(number) as sum_num FROM numbers_input_df_func GROUP BY date_trunc('second', ts); INSERT INTO numbers_input_df_func VALUES (20, "2021-07-01 00:00:00.200"), (22, "2021-07-01 00:00:00.600"); -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('test_numbers_df_func'); SELECT time_window, sum_num FROM out_num_cnt; INSERT INTO numbers_input_df_func VALUES (23,"2021-07-01 00:00:01.000"), (24,"2021-07-01 00:00:01.500"); -- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED | ADMIN FLUSH_FLOW('test_numbers_df_func'); SELECT time_window, sum_num FROM out_num_cnt; DROP FLOW test_numbers_df_func; DROP TABLE numbers_input_df_func; DROP TABLE out_num_cnt;