ARRAY_SUM

This function calculates the sum of all non-null elements of the input. If there are no non-null elements, the function returns 0. The behavior is similar to the SUM aggregate function but operates on an array.

Syntax

ARRAY_SUM(array)

Arguments

NameTypeDescriptionDefault Value

array

numeric

A numeric array

Returns

The sum of all non-null elements of the input. If there are no non-null elements, the function returns 0. A primitive value input is considered to be an array with a single element.


Examples

arrayOutput

array[1, 0.2, 30]

31.2

Transformation job example

SQL

CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT array[],
        ARRAY_SUM(array[]) AS Output
    FROM default_glue_catalog.upsolver_samples.orders_raw_data
    LET array = array[1, 0.2, 30]
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;

Query result

array[]Output

array[1, 0.2, 30]

31.2

Last updated