All Products
Search
Document Center

MaxCompute:ZIP_WITH

Last Updated:Sep 06, 2023

Merges Array a and Array b at the element level based on element positions and a combiner and returns a new array.

Syntax

array<R> zip_with(array<T> <a>, array<S> <b>, function<T, S, R> <combiner>)

Parameters

  • a and b: required. This parameter specifies an array. that T in array<T> and S in array<S> specify the data types of the elements in the arrays. The elements can be of any data type.

  • combiner: required. This parameter specifies the built-in function, user-defined function, or expression that is used to merge Array a and Array b at the element level. The combiner consists of two input parameters. One input parameter must be of the same data type as the elements in Array a. The other input parameter must be of the same data type as the elements in Array b.

Return value

A value of the ARRAY type is returned. The return value varies based on the following rules:

  • The elements in the returned array are at the same positions as the elements in Array a and Array b.

  • If Array a and Array b have different lengths, the null elements are added to the shorter array before the arrays are merged.

Examples

-- The return value is [2, 4, 6, null]. 
select zip_with(array(1,2,3), array(1,2,3,4), (x,y) -> x + y);
Note

In this example, the combination of a hyphen and a closing angle bracket (->) is used. For more information about how to use the combination of a hyphen and a closing angle bracket (->) in Lambda functions, see Lambda functions.

Related functions

ZIP_WITH is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.