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 |
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 code |
---|
extractkv col:column_ref delimiter:string_literal_pattern key:string_literal_pattern valueafter:string_literal_pattern [as:'new_column_name'] |
Parameter | Required? | Data Type | Description |
---|
extractkv | Y | transform | Name of the transform |
col | Y | string | Source column name |
delimiter | Y | string | String literal or pattern that identifies the separator between key-value pairs |
key | Y | string | Pattern that identifies the key to match |
valueafter | Y | string | String literal or pattern after which is located a key's value |
as | N | string | Name of the newly generated column |
Identifies the column to which to apply the transform. You can specify only one column.
Required? | Data Type |
---|
Yes | String (column name) |
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. |
Required? | Data Type |
---|
Yes | String (literal, regular expression, or ) |
Include Page |
---|
| key Parameter |
---|
| key Parameter |
---|
|
Required? | Data Type |
---|
Yes | Single pattern representing the individual keys to extract. |
Include Page |
---|
| valueafter Parameter |
---|
| valueafter Parameter |
---|
|
Required? | Data Type |
---|
Yes | String (literal, regular expression, or ) |
Required? | Data Type |
---|
No | String (column name) |
Include Page |
---|
| EXAMPLE - Extractkv and Unnest Transforms |
---|
| EXAMPLE - Extractkv and Unnest Transforms |
---|
|
D s also |
---|
label | wrangle_transform_extractkv |
---|
|