All Products
Search
Document Center

MaxCompute:ARRAYS_ZIP

Last Updated:Jul 24, 2023

Merges multiple given arrays and returns a struct array, in which the Nth struct contains all the Nth elements of the input arrays.

Syntax

array<struct<T, U, ...>> arrays_zip(array<T> <a>, array<U> <b>[, ...])

Parameters

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

The following data types are supported:

  • TINYINT, SMALLINT, INT, and BIGINT

  • FLOAT and DOUBLE

  • BOOLEAN

  • DECIMAL and DECIMALVAL

  • DATE, DATETIME, TIMESTAMP, IntervalDayTime, and IntervalYearMonth

  • STRING, BINARY, VARCHAR, and CHAR

  • ARRAY, STRUCT, and MAP

Return value

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

  • The Nth struct in the generated struct array contains all the Nth elements of the input arrays. If an array contains less than N elements, null is used as the Nth element of the array.

  • If one or more input arrays are null, null is returned.

Examples

  • Example 1: Merge array(1, 2, 3) and array(2, 3, 4) into a struct array. Sample statement:

    -- The return value is [{0:1, 1:2}, {0:2, 1:3}, {0:3, 1:4}]. 
    select arrays_zip(array(1, 2, 3), array(2, 3, 4));
  • Example 2: Merge array(1, 2, 3) and array(4, 5) into a struct array. Sample statement:

    -- The return value is [{0:1, 1:4}, {0:2, 1:5}, {0:3, 1:null}]. 
    select arrays_zip(array(1, 2, 3), array(4, 5));

Related functions

ARRAYS_ZIP 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.