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:

key1=value1,key2=value2

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

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

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

{"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.

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

col

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

Required?Data Type
YesString (column name)

delimiter

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.

Required?Data Type
Yes

String (literal, regular expression, or )

key

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

valueafter

Required?Data Type
Yes

String (literal, regular expression, or )

as

Required?Data Type
NoString (column name)


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