EXAMPLE - Nest Columns into Arrays
This section provides simple examples of nesting columns into Arrays by extracting values from a column or nesting one or more columns into an Array column.
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:
Transformation Name | |
---|---|
Parameter: Column | msg |
Parameter: Pattern matching elements in the list | `{upper}+` |
Parameter: New column name | acronyms |
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 Wrangle 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}+`
Create by nesting:
You can create arrays by nesting together the values from multiple columns:
num1 | num2 | num3 |
---|---|---|
11 | 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 |
You can nest the values in num1
and num2
into a single array and then to nest the array with num3
:
Anmerkung
If you are nesting a multi-level array, you should nest from the lowest level to the top level.
Transformation Name | |
---|---|
Parameter: Columns1 | num1 |
Parameter: Columns2 | num2 |
Parameter: Nest columns to | Array |
Parameter: New column name | nest1 |
Then, you can perform the nesting of the top-level elements:
Anmerkung
The order in which you list the columns to nest determines the order in which the elements appear in the generated array.
Transformation Name | |
---|---|
Parameter: Columns1 | nest1 |
Parameter: Columns2 | num3 |
Parameter: Nest columns to | Array |
Parameter: New column name | nest2 |
In the generated columns, you notice that all values are quoted, even though these values are integers.
Anmerkung
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:
Transformation Name | |
---|---|
Parameter: Column | nest2 |
Parameter: Find | '"' |
Parameter: Replace | (empty) |
Parameter: Match all occurrences | true |
num1 | num2 | num3 | nest2 |
---|---|---|---|
11 | 12 | 13 | [[11,12],13] |
14 | 15 | 16 | [[14,15],16] |
17 | 18 | 19 | [[17,18],19] |