capture
Add new columns to the data extract by capturing parts of the values from an existing field.
This guide explains how to configure the capture instruction. To learn about another instruction, go back to the Available custom script instructions overview.
Introduction
Use the capture instruction to add new columns to the data extract by capturing parts of the values from an existing column.
Creating a custom script transformation using the capture instruction
To create and configure a custom script using the capture instruction, follow these steps:
-
In the Instructions step, select the capture instruction.
-
To configure the custom script instruction, fill in the following fields. Required fields are marked with an asterisk (*).
-
Field
-
Specify the field which contains the original values. To the left of Source field*, specify the data type of the source field.
-
Pattern
-
Specify a regular expression with a number of capturing groups to match values in the source field.
-
Newfields
-
Specify the names of the new fields to add to the data extract. Specify a new field for each capturing group specified in the regular expression in Pattern*. A value in a new field is what the corresponding capturing group matches in the source field's value within the same row.
-
Include Original
-
Select this checkbox to retain the source field. If you leave this checkbox deselected, the source field is removed during the transformation process.
-
Fill
-
By default, Adverity displays an error if it does not find a match using the regular expression in Pattern*. To prevent this behavior, Adverity can fill values corresponding to non-matching capturing groups with pre-defined values. Specify a list or tuple of the pre-defined values in Default values. In this list or tuple, specify a value for each capturing group you specify in the regular expression in Pattern*.
-
Subtable
-
Enter the name for a subtable that you want to use within this custom script.
A subtable is a temporary table that only exists for this custom script. You can apply additional instructions within the same custom script to the subtable. However, the subtable cannot be used in any other custom scripts.
If a subtable does not exist for the current custom script, the transformation is applied to the data extract, and the enriched data is output into the subtable. If the subtable already exists for the custom script, the subtable is used as the input for the transformation and optionally as the output.
Example
Transformation configuration
-
Field
-
Campaign
-
Pattern
-
(.*)_(\d+)
-
Newfields
-
Campaign type
Campaign ID
-
Include Original
-
Selected
-
Fill
-
unknown
empty
Data table before transformation
Campaign |
Ad Group |
Clicks |
---|---|---|
Brand_1 |
media |
7 |
Brand_2 |
ecommerce |
3 |
Dashboard_1 |
media |
18 |
Dashboard_B |
media|social |
5 |
Dashboard3 |
media |
11 |
Data table after transformation
Campaign |
Ad Group |
Clicks |
Campaign type |
Campaign ID |
---|---|---|---|---|
Brand_1 |
media |
7 |
Brand |
1 |
Brand_2 |
ecommerce |
3 |
Brand |
2 |
Dashboard_1 |
media |
18 |
Dashboard |
1 |
Dashboard_B |
media|social |
5 |
Dashboard |
empty |
Dashboard3 |
media |
11 |
unknown |
empty |