This section describes how to work with the Array data type in the |
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.
Within , you can generate arrays using values from one or more columns to do so.
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:
msg | acronyms |
---|---|
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:
In the final row, the matches on the
"Y"
value. To fix this, you can change the Pattern matching value to the following, which matches on two or more uppercase letters in a row:
`{upper}{upper}+` |
You can create arrays by nesting together the values from multiple columns.
Source:
num1 | num2 | num3 |
---|---|---|
11 | 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 |
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:
num1 | num2 | num3 | nest2 |
---|---|---|---|
11 | 12 | 13 | [[11,12],13] |
14 | 15 | 16 | [[14,15],16] |
17 | 18 | 19 | [[17,18],19] |
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:
listVals | listOfListVals |
---|---|
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:
1000
is the default.The following functions allow you to generate various types of arrays from a column's set of values.
Function | Description | |
---|---|---|
LIST Function | ||
UNIQUE Function | ||
LISTIF Function | ||
ROLLINGLIST Function | ||
RANGE Function |
|
Tip: Additional examples are available in the above links for these functions. |
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:
myObject | myObjectKeys |
---|---|
{"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.
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. |
Function | Description |
---|---|
IN Function | |
ARRAYELEMENTAT Function | |
ARRAYLEN Function | |
ARRAYUNIQUE Function |
Tip: Additional examples are available in the above links for these functions. |
You can use the following functions to perform computations on the values in your arrays:
Function | Description |
---|---|
LISTSUM Function | |
LISTMAX Function | |
LISTMIN Function | |
LISTAVERAGE Function | |
LISTVAR Function | |
LISTSTDEV Function | |
LISTMODE Function |
You can combine arrays together using a variety of methods of combining.
Source:
array1 | array2 |
---|---|
["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:
array1 | array2 | arrayConcat |
---|---|---|
["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:
Function | Description |
---|---|
ARRAYCONCAT Function | |
ARRAYCROSS Function | |
ARRAYINTERSECT Function | |
ARRAYSTOMAP Function | |
ARRAYZIP Function |
Tip: Additional examples are available in the above links for these functions. |
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:
num3 | nest2 |
---|---|
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:
num3 | nest2 |
---|---|
13 | [11,12] |
13 | 13 |
16 | [14,15] |
16 | 16 |
19 | [17,18] |
19 | 19 |
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. |
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:
arrayNested | arrayNested_1 | arrayNested_2 |
---|---|---|
["A",["B","C"],"D"] | ["B","C"] | B |
["H",["I","J",["K","L"]]] | ["I","J",["K","L"]] | I |
["E","F","G"] | F |