zip_with function (Databricks SQL)

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


zip_with(expr1, expr2, func)


  • expr1: An ARRAY expression.

  • expr2: An ARRAY expression.

  • func: A lambda function taking two parameters.


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.


> 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);
> SELECT zip_with(array('a', 'b', 'c'), array('d', 'e', 'f'), (x, y) -> concat(x, y));
 [ad , be, cf]