Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

D toc
Excerpt

Extracts key-value pairs from a source column and writes them to a new column.

Source column must be of String type, although the data can be formatted as other data types. The generated column is of Object type. 

 Your source column (MyKeyValues) is formatted in the following manner:

Code Block
key1=value1,key2=value2

D s
snippetBasic

The following transform extracts the key-value pairs. The key parameter contains a single pattern that matches all keys that you want to extract:

D code
extractkv col: MyKeyValues key:`{alpha}+{digit}` valueafter: '=' delimiter: ','

Output: The generated column contains data that looks like the following:

Code Block
{"key1":"value1","key2":"value2"}

If the source data contained additional keys which were not specified in the transform, those key-value pairs would not appear in the generated column.

D s
snippetParameters
D code

extractkv col:column_ref delimiter:string_literal_pattern key:string_literal_pattern valueafter:string_literal_pattern [as:'new_column_name']

ParameterRequired?Data TypeDescription
extractkvYtransformName of the transform
colYstringSource column name
delimiterYstringString literal or pattern that identifies the separator between key-value pairs
keyYstringPattern that identifies the key to match
valueafterYstringString literal or pattern after which is located a key's value
asNstringName of the newly generated column

D s lang notes

col

Identifies the column to which to apply the transform. You can specify only one column.

D s
snippetusage

Required?Data Type
YesString (column name)

delimiter

Include Page
delimiter Parameter
delimiter Parameter

Tip

Tip: You can insert the Unicode equivalent character for this parameter value using a regular expression of the form /\uHHHH/. For example, /\u0013/ represents Unicode character 0013 (carriage return). For more information, see Supported Special Regular Expression Characters.

D s
snippetusage

Required?Data Type
Yes

String (literal, regular expression, or

D s item
itempattern
)

key

Include Page
key Parameter
key Parameter

D s
snippetusage

Required?Data Type
YesSingle pattern representing the individual keys to extract.

valueafter

Include Page
valueafter Parameter
valueafter Parameter

D s
snippetusage

Required?Data Type
Yes

String (literal, regular expression, or

D s item
pattern
pattern
)

as

Include Page
as Parameter
as Parameter

D s
snippetusage

Required?Data Type
NoString (column name)


D s
snippetExamples

Example - extracting key values from car data and the unnesting into separate columns

Include Page
EXAMPLE - Extractkv and Unnest Transforms
EXAMPLE - Extractkv and Unnest Transforms

D s also
labelwrangle_transform_extractkv