An array is a bracket set of comma-delimited values. The following are valid arrays:
Code Block |
---|
[1,2,3]
["A","B"]
["C",["D","E"],"F",["G",["H","I"]]] |
Ragged arrays: If the number of elements varies between two arrays, they are considered ragged. In the above, all three arrays have a different number of top-level elements (3,2,4).
Nested arrays: When an array element is an array itself, the element is considered a nested array. See the last example above.
Source Arrays
To be recognized as an array, a source column must contain values that are:
- Bracketed by square brackets
- Values in cell are delimited by commas
Such columns are likely to be recognized as Array data type.
For more information, see Array Data Type.
Create Arrays
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:
D trans |
---|
p03Value | acronyms |
---|
Type | ref |
---|
p01Name | Column |
---|
p01Value | msg |
---|
p02Name | Pattern matching elements in the list |
---|
p02Value | `{upper}+` |
---|
p03Name | New column name |
---|
SearchTerm | Extract matches into Array |
---|
|
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:
- An empty input column value renders an empty array.
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: Code Block |
---|
`{upper}{upper}+` |
Create by nesting
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
:
Info |
---|
NOTE: If you are nesting a multi-level array, you should nest from the lowest level to the top level. |
D trans |
---|
p03Value | Array |
---|
Type | ref |
---|
p01Name | Columns1 |
---|
p01Value | num1 |
---|
p02Name | Columns2 |
---|
p02Value | num2 |
---|
p03Name | Nest columns to |
---|
p04Value | nest1 |
---|
p04Name | New column name |
---|
SearchTerm | Nest columns into Objects |
---|
|
Then, you can perform the nesting of the top-level elements:
Info |
---|
NOTE: The order in which you list the columns to nest determines the order in which the elements appear in the generated array. |
D trans |
---|
p03Value | Array |
---|
Type | ref |
---|
p01Name | Columns1 |
---|
p01Value | nest1 |
---|
p02Name | Columns2 |
---|
p02Value | num3 |
---|
p03Name | Nest columns to |
---|
p04Value | nest2 |
---|
p04Name | New column name |
---|
SearchTerm | Nest columns into Objects |
---|
|
In the generated columns, you notice that all values are quoted, even though these values are integers.
Info |
---|
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:
D trans |
---|
p03Value | (empty) |
---|
Type | ref |
---|
p01Name | Column |
---|
p01Value | nest2 |
---|
p02Name | Find |
---|
p02Value | '"' |
---|
p03Name | Replace |
---|
p04Value | true |
---|
p04Name | Match all occurrences |
---|
SearchTerm | Replace text or patterns |
---|
|
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] |
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:
D trans |
---|
p03Value | listOfListVals |
---|
Type | ref |
---|
p01Name | Formula type |
---|
p01Value | Single row formula |
---|
p02Name | Formula |
---|
p02Value | LIST(listVals,1000) |
---|
p03Name | New column name |
---|
SearchTerm | New formula |
---|
|
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:
- The second parameter on the LIST function defines the maximum number of values to write.
1000
is the default. - All values in the generated array are written as String values.
- Quoted values are escaped in the output.
The following functions allow you to generate various types of arrays from a column's set of values.
Function | Description |
---|
LIST Function | D excerpt include |
---|
page | LIST Function |
---|
nopanel | true |
---|
|
|
UNIQUE Function | D excerpt include |
---|
page | UNIQUE Function |
---|
nopanel | true |
---|
|
|
LISTIF Function | D excerpt include |
---|
page | LISTIF Function |
---|
nopanel | true |
---|
|
|
ROLLINGLIST Function | D excerpt include |
---|
page | ROLLINGLIST Function |
---|
nopanel | true |
---|
|
|
RANGE Function | D excerpt include |
---|
page | RANGE Function |
---|
nopanel | true |
---|
|
Info |
---|
NOTE: The lower bound of the range is included, while the upper bound is not. |
|
Tip |
---|
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:
Info |
---|
NOTE: The KEYS function retrieves only the top-level keys from the Object. |
D trans |
---|
p03Value | myObjectKeys |
---|
Type | ref |
---|
p01Name | Formula type |
---|
p01Value | Single row formula |
---|
p02Name | Formula |
---|
p02Value | KEYS(myObject) |
---|
p03Name | New column name |
---|
SearchTerm | New formula |
---|
|
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.
Read from Arrays
You can read values from arrays in your dataset.
Info |
---|
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. |
Tip |
---|
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:
Combine Arrays
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:
D trans |
---|
p03Value | arrayConcat |
---|
Type | ref |
---|
p01Name | Formula type |
---|
p01Value | Single row formula |
---|
p02Name | Formula |
---|
p02Value | ARRAYCONCAT([array1,array2]) |
---|
p03Name | New column name |
---|
SearchTerm | New formula |
---|
|
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:
Tip |
---|
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:
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:
Info |
---|
NOTE: Depending on the number of elements in your arrays, you can significantly increase the size of your dataset. |
Info |
---|
NOTE: If a cell in the source column does not contain an array, an empty value is written into the corresponding row. |
D trans |
---|
Type | ref |
---|
p01Name | column |
---|
p01Value | nest2 |
---|
SearchTerm | Expand Array to rows |
---|
|
Results:
num3 | nest2 |
---|
13 | [11,12] |
13 | 13 |
16 | [14,15] |
16 | 16 |
19 | [17,18] |
19 | 19 |
Info |
---|
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.
Info |
---|
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:
D trans |
---|
p03Value | [2] |
---|
Type | ref |
---|
p01Name | Column |
---|
p01Value | arrayNested |
---|
p02Name | Paths to elements1 |
---|
p02Value | [1] |
---|
p03Name | Paths to elements2 |
---|
p04Value | true |
---|
p04Name | Include original column name |
---|
SearchTerm | Unnest Objects into columns |
---|
|
This one retrieves the first element of the array that is nested as the second element of the array:
D trans |
---|
p03Value | true |
---|
Type | ref |
---|
p01Name | Column |
---|
p01Value | arrayNested |
---|
p02Name | Paths to elements1 |
---|
p02Value | [1][0] |
---|
p03Name | Include original column name |
---|
SearchTerm | Unnest Objects into columns |
---|
|
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 | |