This section describes how to work with the Array data type in the . An array is a set of delimited values. Any individual value in the list can be a separate array, which allows for the creation of nested data arrays.

Array Types

To be recognized as an array, a source column must contain values that are:

Such columns are likely to be recognized as Array data type.

The following are valid arrays:

[1,2,3]
["A","B"]
["C",["D","E"],"F",["G",["H","I"]]]

For more information, see Array Data Type

Create Arrays

Within , you can generate arrays using values from one or more columns to do so.

Create by extraction

You can create an array of values by extracting pattern-based values from a specified column. The following transformation extracts from the msg column a list of all values where all letters are capitalized and places them into the new acronyms column:

msgacronyms
SCUBA, IMHO, is the greatest sport in the world.["SCUBA","IMHO"]

[]
LOL, that assignment you finished is DOA. You need to fix it PDQ.["LOL","DOA","Y","PDQ"]

Notes:

Create by nesting

You can create arrays by nesting together the values from multiple columns.

Source:

num1num2num3
111213
141516
171819

You want to nest the values in num1 and num2 into a single array and then to nest the array with num3:

NOTE: If you are nesting a multi-level array, you should nest from the lowest level to the top level.

Then, you can perform the nesting of the top-level elements:

NOTE: The order in which you list the columns to nest determines the order in which the elements appear in the generated array.

In the generated columns, you notice that all values are quoted, even though these values are integers.

NOTE: Elements that are generated into arrays using a nest transformation are always rendered as quoted values.

You can use the following transformation to remove the quotes from the nest2 column:

After removing the unused nest1 column, the data looks like the following:

num1num2num3nest2
111213[[11,12],13]
141516[[14,15],16]
171819[[17,18],19]

Create from column values

You can use one of several available functions to create arrays from a column's values. 

Source:

listVals
5
TRUE
{"key1":"value1","keys2":"value2"}
[1,2,3]
My String
-5.5

The following transformation generates a new column in which each row contains an array of all of the values of the input column:

Results:

listValslistOfListVals
5["5","TRUE","{\"key1\":\"value1\",\"keys2\":\"value2\"}","[1,2,3]","My String","-5.5"]
TRUE["5","TRUE"," {\"key1\":\"value1\",\"keys2\":\"value2\"}","[1,2,3]","My String","-5.5"]
{"key1":"value1","keys2":"value2"}["5","TRUE"," {\"key1\":\"value1\",\"keys2\":\"value2\"}","[1,2,3]","My String","-5.5"]
[1,2,3]["5","TRUE"," {\"key1\":\"value1\",\"keys2\":\"value2\"}","[1,2,3]","My String","-5.5"]
My String["5","TRUE"," {\"key1\":\"value1\",\"keys2\":\"value2\"}","[1,2,3]","My String","-5.5"]
-5.5["5","TRUE"," {\"key1\":\"value1\",\"keys2\":\"value2\"}","[1,2,3]","My String","-5.5"]


Notes:

The following functions allow you to generate various types of arrays from a column's set of values.

FunctionDescription
LIST Function

UNIQUE Function

LISTIF Function

ROLLINGLIST Function

RANGE Function

NOTE: The lower bound of the range is included, while the upper bound is not.

Tip: Additional examples are available in the above links for these functions.

Create from Object type

You can extract the keys of an Object column into an array of string values. In an Object type, the values are listed in quoted key/value pairs and can be nested. See Object Data Type.

Source:

Suppose your Object data looks like the following:

myObject
{"key1":"value1","key2":"value2", "key3":"value3"}
{"apples":"2", "oranges":"4" }
{"planes":{"boeing":"5","airbus":"4"},"trains":{"amtrak":"1","SP":"2"}, "automobiles":{"toyota":"100","nissan":"50"}}

You can run the following transformation to extract the top-level keys into arrays in a new named column:

NOTE: The KEYS function retrieves only the top-level keys from the Object.

Results:

myObjectmyObjectKeys
{"key1":"value1","key2":"value2","key3":"value3"}["key1","key2","key3"]
{"apples":"2","oranges":"4"}["apples","oranges"]
{"planes":{"boeing":"5","airbus":"4"},"trains":{"amtrak":"1","SP":"2"}, "automobiles":{"toyota":"100","nissan":"50"}}["planes","trains","automobiles"]

For more information, see KEYS Function.

Read from Arrays

You can read values from arrays in your dataset. 

NOTE: After an array has been created, you can append to the array or otherwise combine it with another array. You cannot replace values in the array without breaking apart the array and rebuilding it.

FunctionDescription
IN Function

ARRAYELEMENTAT Function

ARRAYLEN Function

ARRAYUNIQUE Function

Tip: Additional examples are available in the above links for these functions.

Compute from Arrays

You can use the following functions to perform computations on the values in your arrays:

 

FunctionDescription
LISTSUM Function

LISTMAX Function

LISTMIN Function

LISTAVERAGE Function

LISTVAR Function

LISTSTDEV Function

LISTMODE Function

Combine Arrays

You can combine arrays together using a variety of methods of combining.

Source:

array1array2
["1","2","3"]["A","B","C"]
["4","5","6"]["D","E","F"]
["7","8","9"]["G","H","I"]

The following transformation concatenates the above arrays into a single single array:

Results:

array1array2arrayConcat
["1","2","3"]["A","B","C"]["1","2","3","A","B","C"]
["4","5","6"]["D","E","F"] ["4","5","6","D","E","F"]
["7","8","9"]["G","H","I"] ["7","8","9","G","H","I"]

These functions can be used to combine arrays together:

FunctionDescription
ARRAYCONCAT Function

ARRAYCROSS Function

ARRAYINTERSECT Function

ARRAYSTOMAP Function

ARRAYZIP Function


Tip: Additional examples are available in the above links for these functions.

Break out Arrays

Expand arrays into rows

You can break out arrays into individual values using the following transformations. Here is some example data from the nest2 column that was generated earlier. The num3 column is retained for reference:

num3nest2
13[[11,12],13]
16[[14,15],16]
19[[17,18],19]

You can use the following simple transformation to flatten the values in nest2 into individual values in each row:

NOTE: Depending on the number of elements in your arrays, you can significantly increase the size of your dataset.

NOTE: If a cell in the source column does not contain an array, an empty value is written into the corresponding row.

Results:

num3nest2
13[11,12]
1313
16[14,15]
1616
19[17,18]
1919

NOTE: Converting a column of arrays to rows unpacks the top level of the array only. You may have to apply this transformation multiple times.

Unnest array elements into columns

You can break out individual elements of an array into separate columns.

NOTE: Each element that you want broken out into a column must be listed on a separate line in Path to elements.

 Source:

arrayNested
["A",["B","C"],"D"]
["H",["I","J",["K","L"]]]
["E","F","G"]

The following transform retrieves the second and third elements of each array:

This one retrieves the first element of the array that is nested as the second element of the array:

The resulting data should look like the following:

arrayNestedarrayNested_1arrayNested_2
["A",["B","C"],"D"]["B","C"]B
["H",["I","J",["K","L"]]]["I","J",["K","L"]]I
["E","F","G"]F