-- aggregate
SELECT aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x);
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|aggregate(array(1, 2, 3), 0, lambdafunction((namedlambdavariable() + namedlambdavariable()), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))|
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                                        6|
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x, acc -> acc * 10);
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|aggregate(array(1, 2, 3), 0, lambdafunction((namedlambdavariable() + namedlambdavariable()), namedlambdavariable(), namedlambdavariable()), lambdafunction((namedlambdavariable() * 10), namedlambdavariable()))|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                                              60|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

-- array_sort
SELECT array_sort(array(5, 6, 1), (left, right) -> case when left < right then -1 when left > right then 1 else 0 end);
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|array_sort(array(5, 6, 1), lambdafunction(CASE WHEN (namedlambdavariable() < namedlambdavariable()) THEN -1 WHEN (namedlambdavariable() > namedlambdavariable()) THEN 1 ELSE 0 END, namedlambdavariable(), namedlambdavariable()))|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                                                         [1, 5, 6]|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT array_sort(array('bc', 'ab', 'dc'), (left, right) -> case when left is null and right is null then 0 when left is null then -1 when right is null then 1 when left < right then 1 when left > right then -1 else 0 end);
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|array_sort(array(bc, ab, dc), lambdafunction(CASE WHEN ((namedlambdavariable() IS NULL) AND (namedlambdavariable() IS NULL)) THEN 0 WHEN (namedlambdavariable() IS NULL) THEN -1 WHEN (namedlambdavariable() IS NULL) THEN 1 WHEN (namedlambdavariable() < namedlambdavariable()) THEN 1 WHEN (namedlambdavariable() > namedlambdavariable()) THEN -1 ELSE 0 END, namedlambdavariable(), namedlambdavariable()))|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                                                                                                                                                                                                                                    [dc, bc, ab]|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT array_sort(array('b', 'd', null, 'c', 'a'));
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|array_sort(array(b, d, NULL, c, a), lambdafunction((IF(((namedlambdavariable() IS NULL) AND (namedlambdavariable() IS NULL)), 0, (IF((namedlambdavariable() IS NULL), 1, (IF((namedlambdavariable() IS NULL), -1, (IF((namedlambdavariable() < namedlambdavariable()), -1, (IF((namedlambdavariable() > namedlambdavariable()), 1, 0)))))))))), namedlambdavariable(), namedlambdavariable()))|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                                                                                                                                                                                                            [a, b, c, d, NULL]|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

-- cardinality
SELECT cardinality(array('b', 'd', 'c', 'a'));
+------------------------------+
|cardinality(array(b, d, c, a))|
+------------------------------+
|                             4|
+------------------------------+

SELECT cardinality(map('a', 1, 'b', 2));
+----------------------------+
|cardinality(map(a, 1, b, 2))|
+----------------------------+
|                           2|
+----------------------------+

-- concat
SELECT concat('Spark', 'SQL');
+------------------+
|concat(Spark, SQL)|
+------------------+
|          SparkSQL|
+------------------+

SELECT concat(array(1, 2, 3), array(4, 5), array(6));
+---------------------------------------------+
|concat(array(1, 2, 3), array(4, 5), array(6))|
+---------------------------------------------+
|                           [1, 2, 3, 4, 5, 6]|
+---------------------------------------------+

-- element_at
SELECT element_at(array(1, 2, 3), 2);
+-----------------------------+
|element_at(array(1, 2, 3), 2)|
+-----------------------------+
|                            2|
+-----------------------------+

SELECT element_at(map(1, 'a', 2, 'b'), 2);
+------------------------------+
|element_at(map(1, a, 2, b), 2)|
+------------------------------+
|                             b|
+------------------------------+

-- exists
SELECT exists(array(1, 2, 3), x -> x % 2 == 0);
+------------------------------------------------------------------------------------------------+
|exists(array(1, 2, 3), lambdafunction(((namedlambdavariable() % 2) = 0), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------+
|                                                                                            true|
+------------------------------------------------------------------------------------------------+

SELECT exists(array(1, 2, 3), x -> x % 2 == 10);
+-------------------------------------------------------------------------------------------------+
|exists(array(1, 2, 3), lambdafunction(((namedlambdavariable() % 2) = 10), namedlambdavariable()))|
+-------------------------------------------------------------------------------------------------+
|                                                                                            false|
+-------------------------------------------------------------------------------------------------+

SELECT exists(array(1, null, 3), x -> x % 2 == 0);
+---------------------------------------------------------------------------------------------------+
|exists(array(1, NULL, 3), lambdafunction(((namedlambdavariable() % 2) = 0), namedlambdavariable()))|
+---------------------------------------------------------------------------------------------------+
|                                                                                               NULL|
+---------------------------------------------------------------------------------------------------+

SELECT exists(array(0, null, 2, 3, null), x -> x IS NULL);
+----------------------------------------------------------------------------------------------------------+
|exists(array(0, NULL, 2, 3, NULL), lambdafunction((namedlambdavariable() IS NULL), namedlambdavariable()))|
+----------------------------------------------------------------------------------------------------------+
|                                                                                                      true|
+----------------------------------------------------------------------------------------------------------+

SELECT exists(array(1, 2, 3), x -> x IS NULL);
+----------------------------------------------------------------------------------------------+
|exists(array(1, 2, 3), lambdafunction((namedlambdavariable() IS NULL), namedlambdavariable()))|
+----------------------------------------------------------------------------------------------+
|                                                                                         false|
+----------------------------------------------------------------------------------------------+

-- filter
SELECT filter(array(1, 2, 3), x -> x % 2 == 1);
+------------------------------------------------------------------------------------------------+
|filter(array(1, 2, 3), lambdafunction(((namedlambdavariable() % 2) = 1), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------+
|                                                                                          [1, 3]|
+------------------------------------------------------------------------------------------------+

SELECT filter(array(0, 2, 3), (x, i) -> x > i);
+-------------------------------------------------------------------------------------------------------------------------------------+
|filter(array(0, 2, 3), lambdafunction((namedlambdavariable() > namedlambdavariable()), namedlambdavariable(), namedlambdavariable()))|
+-------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                               [2, 3]|
+-------------------------------------------------------------------------------------------------------------------------------------+

SELECT filter(array(0, null, 2, 3, null), x -> x IS NOT NULL);
+--------------------------------------------------------------------------------------------------------------+
|filter(array(0, NULL, 2, 3, NULL), lambdafunction((namedlambdavariable() IS NOT NULL), namedlambdavariable()))|
+--------------------------------------------------------------------------------------------------------------+
|                                                                                                     [0, 2, 3]|
+--------------------------------------------------------------------------------------------------------------+

-- forall
SELECT forall(array(1, 2, 3), x -> x % 2 == 0);
+------------------------------------------------------------------------------------------------+
|forall(array(1, 2, 3), lambdafunction(((namedlambdavariable() % 2) = 0), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------+
|                                                                                           false|
+------------------------------------------------------------------------------------------------+

SELECT forall(array(2, 4, 8), x -> x % 2 == 0);
+------------------------------------------------------------------------------------------------+
|forall(array(2, 4, 8), lambdafunction(((namedlambdavariable() % 2) = 0), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------+
|                                                                                            true|
+------------------------------------------------------------------------------------------------+

SELECT forall(array(1, null, 3), x -> x % 2 == 0);
+---------------------------------------------------------------------------------------------------+
|forall(array(1, NULL, 3), lambdafunction(((namedlambdavariable() % 2) = 0), namedlambdavariable()))|
+---------------------------------------------------------------------------------------------------+
|                                                                                              false|
+---------------------------------------------------------------------------------------------------+

SELECT forall(array(2, null, 8), x -> x % 2 == 0);
+---------------------------------------------------------------------------------------------------+
|forall(array(2, NULL, 8), lambdafunction(((namedlambdavariable() % 2) = 0), namedlambdavariable()))|
+---------------------------------------------------------------------------------------------------+
|                                                                                               NULL|
+---------------------------------------------------------------------------------------------------+

-- map_filter
SELECT map_filter(map(1, 0, 2, 2, 3, -1), (k, v) -> k > v);
+-------------------------------------------------------------------------------------------------------------------------------------------------+
|map_filter(map(1, 0, 2, 2, 3, -1), lambdafunction((namedlambdavariable() > namedlambdavariable()), namedlambdavariable(), namedlambdavariable()))|
+-------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                {1 -> 0, 3 -> -1}|
+-------------------------------------------------------------------------------------------------------------------------------------------------+

-- map_zip_with
SELECT map_zip_with(map(1, 'a', 2, 'b'), map(1, 'x', 2, 'y'), (k, v1, v2) -> concat(v1, v2));
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|map_zip_with(map(1, a, 2, b), map(1, x, 2, y), lambdafunction(concat(namedlambdavariable(), namedlambdavariable()), namedlambdavariable(), namedlambdavariable(), namedlambdavariable()))|
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                       {1 -> ax, 2 -> by}|
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT map_zip_with(map('a', 1, 'b', 2), map('b', 3, 'c', 4), (k, v1, v2) -> coalesce(v1, 0) + coalesce(v2, 0));
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|map_zip_with(map(a, 1, b, 2), map(b, 3, c, 4), lambdafunction((coalesce(namedlambdavariable(), 0) + coalesce(namedlambdavariable(), 0)), namedlambdavariable(), namedlambdavariable(), namedlambdavariable()))|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                          {a -> 1, b -> 5, ...|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

-- reduce
SELECT reduce(array(1, 2, 3), 0, (acc, x) -> acc + x);
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|reduce(array(1, 2, 3), 0, lambdafunction((namedlambdavariable() + namedlambdavariable()), namedlambdavariable(), namedlambdavariable()), lambdafunction(namedlambdavariable(), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                                     6|
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT reduce(array(1, 2, 3), 0, (acc, x) -> acc + x, acc -> acc * 10);
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|reduce(array(1, 2, 3), 0, lambdafunction((namedlambdavariable() + namedlambdavariable()), namedlambdavariable(), namedlambdavariable()), lambdafunction((namedlambdavariable() * 10), namedlambdavariable()))|
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                                                                           60|
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

-- reverse
SELECT reverse('Spark SQL');
+------------------+
|reverse(Spark SQL)|
+------------------+
|         LQS krapS|
+------------------+

SELECT reverse(array(2, 1, 4, 3));
+--------------------------+
|reverse(array(2, 1, 4, 3))|
+--------------------------+
|              [3, 4, 1, 2]|
+--------------------------+

-- size
SELECT size(array('b', 'd', 'c', 'a'));
+-----------------------+
|size(array(b, d, c, a))|
+-----------------------+
|                      4|
+-----------------------+

SELECT size(map('a', 1, 'b', 2));
+---------------------+
|size(map(a, 1, b, 2))|
+---------------------+
|                    2|
+---------------------+

-- transform
SELECT transform(array(1, 2, 3), x -> x + 1);
+---------------------------------------------------------------------------------------------+
|transform(array(1, 2, 3), lambdafunction((namedlambdavariable() + 1), namedlambdavariable()))|
+---------------------------------------------------------------------------------------------+
|                                                                                    [2, 3, 4]|
+---------------------------------------------------------------------------------------------+

SELECT transform(array(1, 2, 3), (x, i) -> x + i);
+----------------------------------------------------------------------------------------------------------------------------------------+
|transform(array(1, 2, 3), lambdafunction((namedlambdavariable() + namedlambdavariable()), namedlambdavariable(), namedlambdavariable()))|
+----------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                               [1, 3, 5]|
+----------------------------------------------------------------------------------------------------------------------------------------+

-- transform_keys
SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + 1);
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), lambdafunction((namedlambdavariable() + 1), namedlambdavariable(), namedlambdavariable()))|
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                      {2 -> 1, 3 -> 2, ...|
+----------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + v);
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), lambdafunction((namedlambdavariable() + namedlambdavariable()), namedlambdavariable(), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                          {2 -> 1, 4 -> 2, ...|
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

-- transform_values
SELECT transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> v + 1);
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
|transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), lambdafunction((namedlambdavariable() + 1), namedlambdavariable(), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                        {1 -> 2, 2 -> 3, ...|
+------------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + v);
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), lambdafunction((namedlambdavariable() + namedlambdavariable()), namedlambdavariable(), namedlambdavariable()))|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                            {1 -> 2, 2 -> 4, ...|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

-- try_element_at
SELECT try_element_at(array(1, 2, 3), 2);
+---------------------------------+
|try_element_at(array(1, 2, 3), 2)|
+---------------------------------+
|                                2|
+---------------------------------+

SELECT try_element_at(map(1, 'a', 2, 'b'), 2);
+----------------------------------+
|try_element_at(map(1, a, 2, b), 2)|
+----------------------------------+
|                                 b|
+----------------------------------+

-- zip_with
SELECT zip_with(array(1, 2, 3), array('a', 'b', 'c'), (x, y) -> (y, x));
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|zip_with(array(1, 2, 3), array(a, b, c), lambdafunction(named_struct(y, namedlambdavariable(), x, namedlambdavariable()), namedlambdavariable(), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                    [{a, 1}, {b, 2}, ...|
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT zip_with(array(1, 2), array(3, 4), (x, y) -> x + y);
+-------------------------------------------------------------------------------------------------------------------------------------------------+
|zip_with(array(1, 2), array(3, 4), lambdafunction((namedlambdavariable() + namedlambdavariable()), namedlambdavariable(), namedlambdavariable()))|
+-------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                           [4, 6]|
+-------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT zip_with(array('a', 'b', 'c'), array('d', 'e', 'f'), (x, y) -> concat(x, y));
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
|zip_with(array(a, b, c), array(d, e, f), lambdafunction(concat(namedlambdavariable(), namedlambdavariable()), namedlambdavariable(), namedlambdavariable()))|
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                                                                                                [ad, be, cf]|
+------------------------------------------------------------------------------------------------------------------------------------------------------------+