All Products
Search
Document Center

MaxCompute:ZIP_WITH

Last Updated:Mar 26, 2026

Merges two arrays element by element into a new array using a combiner. If the arrays have different lengths, null is appended to the shorter array before the combiner is applied.

Syntax

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

The return type is array<R>, where R is the element type returned by the combiner. The elements in the returned array are at the same positions as the elements in Array a and Array b.

Parameters

Parameter Required Description
a Yes The first input array. T specifies the element data type, which can be any supported type.
b Yes The second input array. S specifies the element data type, which can be any supported type.
combiner Yes A built-in function, user-defined function, or expression that merges a and b element by element. It accepts two arguments — one of type T and one of type S — and returns a value of type R.

Examples

The following examples use Lambda expression syntax (->). For details, see Lambda functions.

Arithmetic — uneven arrays

When the arrays have different lengths, null is appended to the shorter array, so the combiner receives null for the missing position.

-- Returns [2, 4, 6, null]
select zip_with(array(1, 2, 3), array(1, 2, 3, 4), (x, y) -> x + y);

Related functions

ZIP_WITH is a complex type function. For more information about functions that process ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.