Вы находитесь на странице: 1из 3

Trifacta Essentials – Student Lab Guide

Chapter 4 – Advanced Operations

Lesson C | Creating columns from existing data | 5 Minutes

Lesson Goals
In this lesson, you will:
• Extract key-value pairs from a column
• Unnest those key-value pairs into new columns

Lesson Instructions

YOUR GOAL: Practice using row data brushing to generate pattern suggestions
for:
o Extracting data into an object
o Unnesting that object into new columns
1. Use the Extractkv transform to create a JSON extractkv col: Items key:
object `{alphanum-underscore}+`
valueafter: ':' delimiter:
`{delim}` as:
The Extractkv transform will identify key- 'extractkv_Items'
value pairs in your data and construct a
column that contains a JSON object. In
Trifacta, maps are an important structure to
understand when you are performing
pivoting or structuring operations on your
dataset.

In the first row of the Items column, select the


text: meat_eggs_seafood. In the second
row of the Items column, select the text:
plants_flowers.

If you want to generate an Extractkv transform,


you cannot select the first key-value pair that
appears in a column.

Scroll to the bottom of the suggestions to find


the suggestion to Extract key value pairs from
this column. Select the Extractkv suggestion
card and click Edit to view Builder.

The Extractkv transform uses pattern-matching


to define keys, values, and the delimiters that
Trifacta Essentials – Student Lab Guide

separate individual key-value pairs. In the


preview, you can view the entire map by clicking
on the right-facing arrow at the edge of a cell.

In this example the Separator between the key


and the value is the colon ‘:’ and there is a
delimiter between each pair which is the pipe
‘|’ character. It generates the new column
“Extractkv_Items.

Add the suggested Extractkv transform to the


recipe.

2. Unnest all key-value pairs from an object
 unnest col:


extractkv_Items keys:
Let’s go back to the extractkv_Items object 'wine_alcohol','meat_eggs_
column. seafood','prepared_food','
plants_flowers','crafts'
Click on the column header and scroll through
the suggestions until you see the suggestion to
Unnest values into new Columns from
extractlistkv_Items. This uses the Unnest
transform.
Select the Unnest suggestion card
and examine the preview.

Notice that the Unnest transform will create


one new column for each key-value pair
contained in the map. When you use column-
selection on an object-type column, the
Unnest transform will automatically create
new columns for all of the key-value pairs in
the map.

Caution: The Unnest transform is sample-


sensitive when applied to objects. If a key-value
pair is not visible in the sample, Trifacta will not
include that key-value pair in the default Unnest
suggestion. After you run a job on a dataset
whose script contains an Unnest transform
applied to an object, you should use the results
profile to verify that you have unnested all of the
key-value pairs contained in your dataset.

2
Trifacta Essentials – Student Lab Guide

Add to recipe.

Вам также может понравиться