GROUP_ARRAY_MOVING_SUM (Lakehouse v1)
The GROUP_ARRAY_MOVING_SUM function calculates the moving sum of input values. The function can take the window size as a parameter. If left unspecified, the function takes the window size equal to the number of input values.
Analyze Syntax
Section titled “Analyze Syntax”func.group_array_moving_sum(<expr>)Analyze Examples
Section titled “Analyze Examples”table.user_id, func.group_array_moving_sum(table.request_num)
| user_id | request_num ||---------|-------------|| 1 | [10,23,43] || 2 | [20,45,70] || 3 | [15,36,62] |SQL Syntax
Section titled “SQL Syntax”GROUP_ARRAY_MOVING_SUM(<expr>)
GROUP_ARRAY_MOVING_SUM(<window_size>)(<expr>)Arguments
Section titled “Arguments”| Arguments | Description |
|---|---|
<window_size> | Any numerical expression |
<expr> | Any numerical expression |
Return Type
Section titled “Return Type”Returns an Array with elements that are of the same type as the original data.
SQL Examples
Section titled “SQL Examples”-- Create a table and insert sample dataCREATE TABLE hits ( user_id INT, request_num INT);
INSERT INTO hits (user_id, request_num)VALUES (1, 10), (2, 15), (3, 20), (1, 13), (2, 21), (3, 25), (1, 30), (2, 41), (3, 45);
SELECT user_id, GROUP_ARRAY_MOVING_SUM(2)(request_num) AS request_numFROM hitsGROUP BY user_id;
| user_id | request_num ||---------|-------------|| 1 | [10,23,43] || 2 | [20,45,70] || 3 | [15,36,62] |