July 30, 2023

tPatternExtract – Docs for ESB 7.x

tPatternExtract

Outputs all data that match a given pattern. You can then implement any required
operation on the extracted data.

The
tPatternExtract extracts from a column all data strings that match a
given Java regular expression.

tPatternExtract Standard properties

These properties are used to configure tPatternExtract running in the Standard Job framework.

The Standard
tPatternExtract component belongs to the Data Quality family.

This component is available in Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

Basic
settings

Schema and Edit schema

A schema is a row description. It defines the number of fields
(columns) to be processed and passed on to the next component. When you create a Spark
Job, avoid the reserved word line when naming the
fields.

Built-In: You create and store the schema locally for this component
only.

Repository: You have already created the schema and stored it in the
Repository. You can reuse it in various projects and Job designs.

Column to check

Select the column you want to analyze.

PROPERTY

The pattern against which you want to check the data is either
Built-in or stored remotely in the
Repository.

Built-in: You can enter a pattern regex in the
Pattern Regex field and store it locally for
this component only.

Repository: From the
Pattern Selector, select the pattern against
which you want to check the data.

These patterns are retrieved from the DQ Repository of Talend Studio.
The list includes the system and user-defined patterns.

Advanced
settings

tStat
Catcher
Statistics

Select this check box to collect log data at
the component level.

Global
Variables

Global Variables

NB_LINE: the number of rows read by an input component or
transferred to an output component. This is an After variable and it returns an
integer.

NB_LINE_OK: the number of rows matching a given pattern.
This is an After variable and it returns an integer.

NB_LINE_REJECT: the number of rows not matching a given
pattern. This is an After variable and it returns an integer.

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see
Talend Studio

User Guide.

Usage

Usage rule

This component is usually used as an intermediate component, and it requires an
input component and an output component.

Limitation

When exporting a Job using
tPatternExtract with a user-defined pattern
stored in the DQ Repository, you must export the
pattern with the Job. Otherwise, the pattern will switch to Built-in
mode when importing the Job in another project.

When importing a Job using tPatternExtract with a
system pattern, the pattern will switch to Built-in mode.

For more information about importing Jobs with
data profiling items in Talend Studio, see the
documentation on Talend Help Center (https://help.talend.com).

Extracting only the data that corresponds to a defined pattern from
a delimited file

This scenario applies only to Talend Data Management Platform, Talend Big Data Platform, Talend Real Time Big Data Platform, Talend Data Services Platform, Talend MDM Platform and Talend Data Fabric.

This scenario describes a four-component Job where the tExtractPattern component is used to extract only
customers’ email addresses (that match the Email
address
pattern) from a delimited file that holds different customer
data. Then it writes the extracted data into another delimited file. A tFilterColumns component is used to adapt the output
schema.

tPatternExtract_1.png

In this scenario, the delimited file holds names, email addresses and telephone numbers,
all in a single column: Name_Telephone_Address. The following shows an extract of the
input file:

tPatternExtract_2.png

Setting up the Job

  1. Drop the following components from the Palette to the design
    workspace: tFileInputDelimited, tPatternExtract, tFilterColumns, and
    tFileOutputDelimited.
  2. Connect the tFileInputDelimited component to the
    tPatternExtract
    component using a Row > Main connection.
  3. Connect the tPatternExtract component to the
    tFilterColumns
    component using the Row > Matching
    Data
    connection.
  4. Connect the tFilterColumns component to the
    tFileOutputDelimited component using a
    Row > Main connection.

Configuring the components

  1. Double-click tFileInputDelimited to display its Basic settings view and define the component properties,
    including the input file name, the number of header rows to skip, and the
    schema.

    tPatternExtract_3.png

    1. Click the Edit Schema to create the
      schema.
    2. Click [+] to add a
      Name__Telephone_Address to the schema and
      click OK to validate.

      tPatternExtract_4.png

  2. Double-click tPatternExtract to display its Basic
    settings
    view and define the component properties.

    tPatternExtract_5.png

    1. From the Column to check list, select the column
      you want to check its data against the defined pattern,
      Name_Telephone_Address
      in this example.
    2. From the PROPERTY list, select
      Repository to check the data against a
      pattern from the DQ Repository.
    3. Click the […] button next to the
      PROPERTY field and select Regex > internet > Email Address from the Pattern Selector.
  3. In the Basic settings
    view of the tFilterColumns component,
    click the […] button next to Edit schema to open the Schema dialog box.

    tPatternExtract_6.png

  4. Select the column of interest from the Input schema, and click
    the right arrow button to copy the column to the output schema. Then, click
    OK to close the dialog box.
  5. Double-click tFileOutputDelimited to display its Basic settings view and define the component properties.

    tPatternExtract_7.png

    1. In the File Name field, specify the path to the
      file you want to write the output data to.
    2. Define the row and field separators in the corresponding fields, if
      any. In this example, we want to separate customers’ email addresses by
      semicolons.

Executing the Job

Save your Job and press F6
to execute it.

Customers’ email addresses are extracted from the selected column according to the
defined Email pattern and written in the output file using semicolons as row
separators. You can then, for example, send an email to all your customers in one
go.

tPatternExtract_8.png


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x