Extracting one or more values from within a column of values can turn data into meaningful and discrete information. This section describes how to extract column data, the methods for which may vary depending on the data type. |
Extract and split transformations do not do the same thing:
An extract transformation matches literal or pattern values from a source column and stores it in a separate column.
NOTE: The source column is untouched by extract transformations. |
In the Transformer page, you can use the following methods to extract values:
Method | Description |
---|---|
By selection | Select part of a value in the data grid to prompt a series of suggestions on what to do with the data. Typically, extract options are near the top of the suggestions when you select part of a value. |
By column menu | From the menu to the right of the column, select Extract and a sub-menu item to begin configuring a transformation. |
By Transformer toolbar | At the top of the data grid, click the Extract icon in the Transformer toolbar to begin configuring extract transformations. |
By Search panel | In the Search panel, enter extract to build a transformation from scratch. |
A primary use of extraction is to remove literal or patterned values of text from a column of values. Suppose your dataset included a column of LinkedIn updates. You can use one of the following methods to extract keywords from these values.
The following example transformation extracts the word #bigdata
from the column msg_LinkedIn
:
Notes:
option
parameter identifies that the pattern to match is a custom one specified by the user.Number of matches to extract
parameter defaults to 1
, meaning that the transformation extracts a maximum of one value from each cell. This value can be set from 1-50. You can generate a new column of values extracted from a source column by entering example values to match with source values. Values with similar patterns may also be matched based on your entered example value.
Tip: This method provides an easy way to build pattern-based matching for values in a source column. |
For more information on transformation by example, see Overview of TBE.
Within the extract transformation, you can specify literals or patterns before or after which the match is found. This method can be used to remove parts of each cell value from erroneously matching on the literal or pattern that is desired.
The following example extracts the second three-digit element of a phone number, skipping the area code:
You can also do pattern-based extractions using or regular expressions.
The following example extracts all words that begin with #
in the msg_LinkedIn
column:
Notes:
The Text to extract
parameter has changed:
Element | Description |
---|---|
Two back-ticks ( | Indicate that the expression between them represents a |
\# | The slash indicates that the character right after it should be interpreted as a character only; it should not be interpreted as any special character in the pattern. |
{alphanum-underscore} | This |
+ | Adding the plus sign after the above character signifies that the pattern can match on a sequence of alphanumeric or underscore characters of one or more length. |
Number of matches to extract
parameter has been increased to grab up to 50 hashtags.Option | Description | |
---|---|---|
Number of patterns to extract | Set this value to the total number of patterns you wish to extract.
The default is | |
Ignore case | By default, pattern matching is case-sensitive. Select this checkbox to ignore case when matching. | |
Ignore matches between | You can enter a pattern here to describe any patterns that should not be part of any match. This option is useful if you have multiple instances of text but want to ignore the first one, for example. |
In your pattern expressions, you can use the vertical pipe character (|
) to define multiple patterns to find. The following example extracts any value from the myDate
column that ends in 7
pr in 8
:
You can use the vertical pipe in both and regular expressions.
You can extract the first or last set of characters from a column into a new column. In the following example, the first five characters from the ProductName
column are extracted into a new product identifier column:
You can change the Option value to Last characters
to extract from the right side of the column value.
If you need to remove the characters that you extracted, you can use the following transformation. In this case, the first five characters, which were extracted in the previous transformation, are removed:
You can extract values between specified index positions within a set of column values. In the following example, the text between the fifth and tenth characters in a column are extracted to a new column.
Tip: This extraction method is useful if the content before and after the match area is inconsistent and cannot be described using patterns. If it is consistent, you should use the Extract text or pattern transformation. |
You can perform extractions that are specific to a data type or based on failures of the data to match a specified data type.
You can use functions to extract values from Datetime columns. The example below extracts the year value from the myDate
column:
The following functions can be used to extract values from a Datetime column, as long as the values are present in the formatted date:
Function Name | Description |
---|---|
DAY Function | |
MONTH Function | |
YEAR Function | |
HOUR Function | |
MINUTE Function | |
SECOND Function |
You can also reformat the whole Datetime column using the DATEFORMAT
function. The following reformats the column to show only the two-digit year:
You can extract numerical data from text values. In the following example, the first number is extracted from the address
column, which would correspond to extracting the street number for the address:
Empty values in this new column might indicate a formatting problem with the address.
Tip: If you set the number of patterns to extract to |
Using functions, you can extract specific elements of a valid URL. The following transformation pulls the domain values from the myURL
column:
In some cases, the function may not return values. For example, the SUBDOMAIN function returns empty values if there is no sub-domain part of the URL.
The following functions can be used to extract values from a set of URLs:
Function Name | Description |
---|---|
HOST Function | |
DOMAIN Function | |
SUBDOMAIN Function | |
URLPARAMS Function |
You can extract query parameter values from an URL. The following example extracts the store_id
value from the storeURL
field value:
If your data includes sets of arrays, you can extract array elements into columns for each key, with the values written to each key column.
Suppose your restaurant dataset includes a set of characteristics in the restFeatures
column in the following JSON format:
{ "Credit": "Y", "Accessible": "Y", "Restrooms": "Y", "EatIn": "Y", "ToGo": "N", "AlcoholBeer": "Y", "AlcoholHard": "N", "TotalTables": "10", "TotalTableSeats": "36", "Counter": "Y", "CounterSeats": "8" } |
You can use the following transformation to extract the values from TotalTableSeats
and CounterSeats
into separate columns:
After the above is executed, you can perform a simple sum of the TotalTableSeats
and CounterSeats
columns to determine the total number of seats in the restaurant.
In some cases, your data may contain arrays of repeated key-value pairs, where each pair would exist on a separate line. Suppose you have a column called, Events
, which contains date and time information about the musician described in the same row of data. The Events
column might look like the following:
[{"Date":"2018-06-15","Time":"19:00"},{"Date":"2018-06-17","Time":"19:00"},{"Date":"2018-06-19","Time":"20:00"},{"Date":"2018-06-20","Time":"20:00"}] |
The following transformation creates a separate row for each entry in the Events
column, populating the other fields in the new rows with the data from the original row:
NOTE: This type of transformation can significantly increase the size of your dataset. |
You can also extract sets of values into an array list of values.
Tip: This transformation is useful for extracting types or patterns of information from a single column. |
Using , you can extract the values of the column to form a new column of arrays. The following example shows the usage of {any} pattern to extract the cell values and form a new array column.
Transformation:
Results:
Before | After |
---|---|
socks, socks, socks | ["socks", "socks", "socks"] |
pants, pants | ["pants", "pants"] |