zip_with function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Merges the arrays in expr1 and expr2, element-wise, into a single array using func.

Syntax

zip_with(expr1, expr2, func)

Arguments

  • expr1: An ARRAY expression.

  • expr2: An ARRAY expression.

  • func: A lambda function taking two parameters.

Returns

An ARRAY of the result of the lambda function.

If one array is shorter, nulls are appended at the end to match the length of the longer array before applying func.

Examples

> SELECT zip_with(array(1, 2, 3), array('a', 'b', 'c'), (x, y) -> (y, x));
 [{a, 1}, {b, 2}, {c, 3}]
> SELECT zip_with(array(1, 2), array(3, 4), (x, y) -> x + y);
 [4,6]
> SELECT zip_with(array('a', 'b', 'c'), array('d', 'e', 'f'), (x, y) -> concat(x, y));
 [ad , be, cf]