ETL Metadata Injection
Metadata injection inserts data from various sources into a transformation at runtime. This insertion reduces repetitive ETL tasks.
For example, you might have a simple transformation to load transaction data values from a supplier, filter specific values, and output them to a file. If you have more than one supplier, you would need to run this simple transformation for each supplier. Yet, with metadata injection, you can expand this simple repetitive transformation by inserting metadata from another transformation that contains the ETL Metadata Injection step. This step coordinates the data values from the various inputs through the metadata you define. This process reduces the need for you to adjust and run the repetitive transformation for each specific input.
The repetitive transformation is known as the template transformation. The template transformation is called by the ETL Metadata Injection step. You will create a transformation to prepare what common values you want to use as metadata and inject these specific values through the ETL Metadata Injection step as shown in the following diagram:
We recommend the following basic procedure for using this step to inject metadata:
- Optimize your data for injection, such as preparing folder structures and inputs.
- Develop transformations for the repetitive process (the template transformation), for metadata injection through the ETL Metadata Injection step, and for handling multiple inputs.
The metadata is injected into the template transformation through any step that supports metadata injection. See Steps Supporting Metadata Injection for which steps support metadata injection.
General
Enter the following information in the transformation step fields:
Field | Description |
---|---|
Step Name | Specifies the unique name of the ETL Metadata Injection step on the canvas. You can customize the name or leave it as the default. |
Transformation |
Specify your template transformation by entering in its path. Click Browse to display and enter the path details using the Virtual File System Browser. If you select a transformation that has the same root path as the current transformation, the variable ${Internal.Entry.Current.Directory} will automatically be inserted in place of the common root path. For example, if the current transformation's path is /home/admin/transformation.ktr and you select a transformation in the folder /home/admin/path/sub.ktr than the path will automatically be converted to ${Internal.Entry.Current.Directory}/path/sub.ktr. If you are working with a repository, specify the name of the template transformation in your repository. If you are not working with a repository, specify the XML file name of the template transformation on your system. Template transformations previously specified by reference are automatically converted to be specified by name within the Pentaho Repository. |
Options
The ETL Metadata Injection step features the two tabs with fields. Each tab is described below.
Inject Metadata Tab
The columns of the table in this tab specifies what fields in the template transformation are injected with metadata. The following table describes these columns:
Column | Description |
---|---|
Target injection step key | Lists the available fields in each step of the template transformation that can be injected with metadata. |
Target description | Describes how the target fields relate to their target steps. |
Source step | Lists the step associated with the fields to be injected into the target fields as metadata. |
Source field | Lists the fields to be injected into the target fields as metadata. |
To specify the source field as metadata to be injected, perform the following steps:
- In the Target injection step key column, double-click the field for which you want to specify a source field. The Source field dialog box opens.
- Select a source field and click OK.
- Optionally, select Use constant value to specify a constant value for the injected metadata through one of the following actions:
- Manually entering a value.
- Using an internal variable to set the value (${Internal.Step.Unique.Count} for example).
- Using a combination of manually specified values and parameter values (${FILE_PREFIX}_${FILE_DATE}.txt for example).
Injecting Metadata into the ETL Metadata Injection Step
For injecting metadata into the ETL Metadata Injection step itself, the following exceptions apply:
- To inject a method for how to specify a field (such as by FILENAME, REPOSITORY_BY_NAME, or REPOSITORY_BY_REFERENCE), set a TRANS_SPECIFICATION_METHOD constant to the field of an input step. You can then map the field as a source to the TRANS_SPECIFICATION_METHOD constant in the ETL Metadata Injection step.
- The target field for the ETL Metadata Injection step inserting the metadata into the original injection is defined by [GROUP NAME].[FIELD NAME]. For example, if the GROUP NAME is 'OUTPUT_FIELDS' and the FIELD NAME is 'OUTPUT_FIELDNAME', you would set the target field to 'OUTPUT_FIELDS.OUTPUT_FIELDNAME'.
Options Tab
Enter the following optional settings:
Option | Description |
---|---|
Step to read from (optional) | Optionally, select a step in your template transformation to pass data directly to a step following the ETL Metadata Injection step in your current transformation. |
Field name | If Step to read from is selected, enter the name of the field passed directly from the step in the template transformation. |
Type | If Step to read from is selected, select the type of the field passed directly from the step in the template transformation. |
Length | If Step to read from is selected, enter the length of the field passed directly from the step in the template transformation. |
Precision | If Step to read from is selected, enter the precision of the field passed directly from the step in the template transformation. |
Optional target file (KTR after injection) | For initial transformation development or debugging, specify an optional file for creating and saving a transformation of your template after metadata injection occurs. The resulting transformation will be your template transformation with the metadata already injected as constant values. |
Streaming source step |
Select a source step in your current transformation to directly pass data to the Streaming target step in the template transformation. |
Streaming target step |
Select the target step in your template transformation to receive data directly from the Streaming source step. |
Run resulting transformation |
Select to inject metadata and run the template transformation. If this option is not selected, metadata injection occurs, but the template transformation does not run. |
Example
In this example, you have a template transformation to load transaction data values from a supplier’s spreadsheet, filter specific values to examine, and output them to a text file. The template transformation is injected with metadata from spreadsheets created by you.
In this example, we show you how to use metadata injection through the following steps:
- Step 1: Create Sample Data – the folder structure and spreadsheet files used to show how data can be set up for metadata injection
- Step 2: Develop Your Transformations – the transformations for the main process (the template transformation), metadata injection through the ETL Metadata Injection step, and dealing with multiple supplier files
- Step 3: Run and Examine Results – the single source output text file and logging
This example assumes a basic understanding of working with transformations and steps.
Step 1: Create Sample Data
Data files are frequently uploaded from various sources. For this step, we model a situation where two suppliers have uploaded spreadsheets into a data/in folder.
When using metadata injection, you usually want to focus on a subset of data values common to all your input files. For this example, we derive metadata for the following values:
- Transaction date
- Transaction invoice number
- Net value of the transaction
- Currency used in the transaction
The metadata for these values and the output target text file are created and maintained in the metadata folder.
- Create a new folder named Pentaho_Metadata_Injection_Example on your computer, and then create the following folder structure inside it.
- Create a spreadsheet for supplier #1 in Microsoft Excel, and save it as data_format_a.xlsx in the data/in/supplier1 folder.
Tx Date and Time | Check | Inv | Price | Net | VAT | Gross | VATP | Cur |
---|---|---|---|---|---|---|---|---|
01/26/2016 07:24:00 | 12345 | 9406 | 1.13 | 62.69 | 11.91 | 74.6 | 19 | EUR |
01/26/2016 07:31:00 | 12346 | 9407 | 1.13 | 54.63 | 10.38 | 65.01 | 19 | EUR |
- Create a spreadsheet for supplier #2 in Microsoft Excel, and save it as data_format_b.xlsx in the data/in/supplier2 folder.
TransferDataTime | Check | Inv | Cur | VAT | Gross | VATP | Net |
---|---|---|---|---|---|---|---|
01/26/2016 07:23:00 | 800901 | 3711 | EUR | 8.95 | 56.06 | 19 | 47.11 |
01/26/2016 07:30:00 | 800927 | 3712 | EUR | 0.94 | 5.89 | 19 | 4.95 |
01/26/2016 07:32:00 | 800990 | 3713 | EUR | 15.38 | 96.36 | 19 | 80.98 |
- Create two tabs in a spreadsheet of metadata fields for suppliers, and save it as metadata_suppliers.xlsx in the metadata folder.
- The s upplier1 tab.
Name | Type | Length | Precision | Trim type | Repeat | Format | Currency | Decimal | Grouping | Target field |
---|---|---|---|---|---|---|---|---|---|---|
Tx Date and Time | Date | -1 | -1 | none | N | yyyy/MM/dd HH:mm:ss | transaction_date | |||
Check | Integer | -1 | -1 | none | N | |||||
Inv | Integer | -1 | -1 | none | N | transaction_invoice | ||||
Price | BigNumber | 8 | 2 | none | N | , | . | |||
Net | BigNumber | 8 | 2 | none | N | , | . | transaction_net | ||
VAT | BigNumber | 8 | 2 | none | N | , | . | |||
Gross | BigNumber | 8 | 2 | none | N | , | . | |||
VATP | BigNumber | 2 | 1 | none | N | , | . | |||
Cur | String | 3 | -1 | none | N | transaction_cur |
- The supplie r2 tab.
Name | Type | Length | Precision | Trim type | Repeat | Format | Currency | Decimal | Grouping | Target field |
---|---|---|---|---|---|---|---|---|---|---|
TransferDateTime | Date | none | N | transaction_date | ||||||
Check | Number | none | N | |||||||
Inv | Number | none | N | transaction_invoice | ||||||
Cur | String | none | N | transaction_cur | ||||||
VAT | Number | none | N | |||||||
Gross | Number | none | N | |||||||
VATP | Number | none | N | |||||||
Net | Number | none | N | transaction_net |
- Create a spreadsheet of metadata fields for targets, and save it as metadata_target.xlsx in the metadata folder.
Name | Type | Format | Length | Precision | Currency | Decimal | Group | Trim type | Null |
---|---|---|---|---|---|---|---|---|---|
supplier | String | both | |||||||
source_filename | String | none | |||||||
source_row | Integer | # | none | ||||||
transaction_date | Date | yyyy-MM-dd | none | ||||||
transaction_invoice | BigNumber | # | -1 | -1 | none | ||||
transaction_net | BigNumber | #.## | -1 | -1 | none | ||||
transaction_cur | String | 3 | both |
Step 2: Develop Your Transactions
You need to develop a transformation for the main repetitive process, which is often known as the template transform. For this example, you need a transformation (process_supplier_file) to process the transactions in each supplier’s file. Then, the metadata needs to be injected from a transformation (inject_supplier_metadata) developed with the ETL Metadata Injection step. The ETL Metadata Injection step calls the template transformation. Since this example is for inserting data from multiple files, the metadata injection transformation needs to be called from another transformation (process_all_suppliers) per each supplier file.
All total, three transformations need to be developed:
- Template Transformation – The main repetitive transformation for processing the data per each supplier’s spreadsheet.
- Metadata Injection Transformation – The transformation defining the structure of the metadata and how it is injected into the main transformation.
- Transformation for All Suppliers – The transformation going through all the suppliers’ spreadsheets, calling the metadata injection transformation per each supplier, and logging the entire process (for possible troubleshooting, if needed).
Template Transformation
With metadata injection, you develop your repetitive, template transformation as you would normally. The main difference is how the settings for each step pertains to the metadata injection, instead of data values of a single specific source.
- Open a new transformation and save it as process_supplier_file.ktr to the transformations folder.
- Drag a Microsoft Excel Input step onto the canvas.
- Change Spread sheet type (engine) to Excel 2007 XLSX (Apache POI), and fill out the following values in the Additional output fields tab.
Field | Value |
---|---|
Full filename field | processed_filename |
Sheet row nr field | source_row |
Short filename field | source_filename |
- Drag a Select values step onto the canvas and connect a hop from Microsoft Excel Input to Select values.
- Drag a Get Variables step onto the canvas and connect a hop from Select values to Get Variables, while selecting Main output of step. Also fill out the following values in the Fields table.
Field | Value |
---|---|
Name | supplier |
Variable | ${supplier} |
Type | String |
Trim type | none |
- Drag a Text file output step onto the canvas and connect a hop from Get Variables to Text file output. Also fill out the following values in the File and Content tabs.
Field | Value |
---|---|
Filename (in File tab) | ${Internal.Entry.Current.Directory}/../data/out/processed_data |
Include date in filename? (in File tab) | enable |
Add filenames to result (in File tab) | disable |
Append (in Content tab) | enable |
- Save your process_supplier_file.ktr file.
Metadata Injection Transformation
For this example, our metadata values are maintained in separate spreadsheet files. You need to create a transformation to extract in these values, prepare them for the injection, and then insert them into the template transformation through the ETL Metadata Injection step, as shown in the following figure:
Extract the Metadata
For this example, you need to define the input files, access the metadata, and structure the output based on this metadata.
- Open a new transformation and save it as inject_supplier_metadata.ktr to the transformations folder.
- Drag a Get row from result step to the canvas, and fill out the following values in the Fields table.
# | Fieldname | Type | Length |
---|---|---|---|
1 | supplier | String | 500 |
2 | folderName | String | 500 |
- Drag a Microsoft Excel Input step onto the canvas, name the step Metadata Suppliers.
- Browse to Add the ${Internal.Entry.Current.Directory}/../metadata/metadata_suppliers.xlsx file in the Files tab. After adding the file, you can verify its path by clicking Show filenames...
- Change Spread sheet type (engine) to Excel 2007 XLSX (Apache POI), and fill out the following values in the !Fields tab table.
# | Name | Type | Length | Precision | Trim type | Repeat |
---|---|---|---|---|---|---|
1 | Name | String | -1 | -1 | none | N |
2 | Type | String | -1 | -1 | none | N |
3 | Length | Integer | -1 | -1 | none | N |
4 | Precision | Integer | -1 | -1 | none | N |
5 | Trim type | String | -1 | -1 | none | N |
6 | Repeat | String | -1 | -1 | none | N |
7 | Format | String | -1 | -1 | none | N |
8 | Currency | String | -1 | -1 | none | N |
9 | Decimal | String | -1 | -1 | none | N |
10 | Grouping | String | -1 | -1 | none | N |
11 | Target field | String | -1 | -1 | none | N |
- In the Additional output fields tab, set Sheetname field to metadata_supplier.
- Drag another Microsoft Excel Input step onto the canvas, name the step Metadata Target.
- Add the ${Internal.Entry.Current.Directory}/../metadata/metadata_target.xlsx file in the Files tab. After adding the file, you can verify its path by clicking Show filenames...
- Change Spread sheet type (engine) to Excel 2007 XLSX (Apache POI), and fill out the following values in the !Fields tab table.
# | Name | Type | Length | Precision | Trim type | Repeat |
---|---|---|---|---|---|---|
1 | Name | String | -1 | -1 | none | N |
2 | Type | String | -1 | -1 | none | N |
3 | Format | String | -1 | -1 | none | N |
4 | Length | Integer | -1 | -1 | none | N |
5 | Precision | Integer | -1 | -1 | none | N |
6 | Currency | String | -1 | -1 | none | N |
7 | Decimal | String | -1 | -1 | none | N |
8 | Group | String | -1 | -1 | none | N |
9 | Trim type | String | -1 | -1 | none | N |
10 | Null | String | -1 | -1 | none | N |
- In the Additional output fields tab, set Sheetname field to metadata_supplier.
Prepare the Metadata
With the supplier files specified and the metadata accessed, you need to prepare this information to be injected into the main transformation.
- Drag a Join Rows step to the canvas, and connect a hop from the Get rows from result step and Join Rows. Also connect a hop from the Metadata Suppliers step to Join Rows.
- Set The condition in Join Rows to metadata_supplier = supplier.
- Drag an Add constants step to the canvas, and connect a hop from Get rows from result to Add constants. When the Warning dialog appears, click Copy.
- Fill out the Fields table of Add constants with the following values.
# | Name | Type | Value | Set empty string? |
---|---|---|---|---|
1 | wildcard_include | String | .* | N |
2 | wildcard_exclude | String | N |
- Drag a Get file names step to the canvas, and connect a hop from Add constants to Get file names. Also fill out the following values in the File tab.
Field | Value |
---|---|
Filename is defined in a field? | enable |
Get filename from field | folderName |
Get wildcard from field (RegExp) | wildcard_include |
Exclude wildcard field | wildcard_exclude |
Inject the Metadata
With the metadata prepared, you need to associate it with the main transformation for it to be inserted at runtime.
- Drag the ETL Metadata Injection step to the canvas, and connect three hops:
- From Join Rows to ETL Metadata Injection
- From Get File Names to ETL Metadata Injection
- From Metadata Target to ETL Metadata Injection
- In the File tab of the step properties, set ${Internal.Entry.Current.Directory}/process_supplier_file.ktr to Use a file for the transformation template.
- Click Validate and Refresh.
- In the Inject Metadata tab, set the Source step and Source field for the following fields.
Target injection step, key | Source step | Source field | |
---|---|---|---|
Microsoft Excel Input > FIELDS > NAME | Join Rows | Name | |
Microsoft Excel Input > FIELDS > LENGTH | Join Rows | Length | |
Microsoft Excel Input > FIELDS > PRECISION | Join Rows | Precision | |
Microsoft Excel Input > FIELDS > FORMAT | Join Rows | Format | |
Microsoft Excel Input > FIELDS > CURRENCY | Join Rows | Currency | |
Microsoft Excel Input > FIELDS > DECIMAL | Join Rows | Decimal | |
Microsoft Excel Input > FIELDS > GROUP | Join Rows | Grouping | |
Microsoft Excel Input > FIELDS > REPEAT | Join Rows | Repeat | |
Microsoft Excel Input > FIELDS > TYPE | Join Rows | Type | |
Microsoft Excel Input > FILENAME_LINES > FILENAME | Get File Names | filename | |
Select values > METAS > META_NAME | Join Rows | Name | |
Select values > METAS > RENAME | Join Rows | Target field | |
Text file output > OUTPUT_FIELDS > OUTPUT_FIELDNAME | Metadata Target | Name | |
Text file output > OUTPUT_FIELDS > OUTPUT_FORMAT | Metadata Target | Format | |
Text file output > OUTPUT_FIELDS > OUTPUT_LENGTH | Metadata Target | Length | |
Text file output > OUTPUT_FIELDS > OUTPUT_PRECISION | Metadata Target | Precision | |
Text file output > OUTPUT_FIELDS > OUTPUT_CURRENCY | Metadata Target | Currency | |
Text file output > OUTPUT_FIELDS > OUTPUT_DECIMAL | Metadata Target | Decimal | |
Text file output > OUTPUT_FIELDS > OUTPUT_GROUP | Metadata Target | Group | |
Text file output > OUTPUT_FIELDS > OUTPUT_NULL | Metadata Target | Null | |
Text file output > OUTPUT_FIELDS > OUTPUT_TYPE | Metadata Target | Type | |
Text file output > OUTPUT_FIELDS > OUTPUT_TRIM | Metadata Target | Trim type |
- Save your inject_supplier_metadata.ktr file.
Transformation for All Suppliers
Since we have multiple input sources, we need a transformation to run through each source and inject the metadata. Each input source is specified through a variable in a Transformation Executor step, which calls to the metadata injection transformation.
- Open a new transformation and save it as process_all_suppliers.ktr to the transformations folder.
- Drag a Get Subfolder names step to the canvas, and add the ${Internal.Entry.Current.Directory}/../data/in folder in the Folder tab.
- Drag a Select values step to the canvas, and connect a hop from Get Subfolder names to Select values.
- Fill out the following values in the Fields table of the Select & Alter tab.
# | Fieldname | Rename to |
---|---|---|
1 | folderName | |
2 | short_folderName | supplier |
- Drag a Text file output step to the canvas.
- Fill out the following values in the File tab.
Field | Value |
---|---|
Filename | ${Internal.Entry.Current.Directory}/../logging/log |
Include date in filename? | enable |
Include time in filename? | enable |
- Drag a Transformation Executor step to the canvas, connect a hop from Select values to Transformation Executor, then select Main output of step in the context menu.
- Also, connect a hop from Transformation Executor to Text file output, then select This output will contain the execution results in the context menu.
- Fill out the following values in the Parameters and Execution results tabs.
Field | Value |
---|---|
File name | ${Internal.Entry.Current.Directory}/inject_supplier_metadata.ktr |
Variable / Parameter name (in Parameters tab) | supplier |
Field to use (in Parameters tab) | supplier |
The target step for the execution results (in the Execution Results tab) | Text file output |
- Save your process_all_suppliers.ktr file.
Step 3: Run and Examine Results
You run the entire process for all the supplier file by running the process_all_suppliers transformation, which runs the inject_supplier_metadata transformation for each supplier input file. The inject_supplier_metadata transformation then runs the template process_supplier_file transformation.
These transformations create a single source text output file in the data/out folder. The logs generated by the process_all_suppliers transformation are in the logging folder.
- Run the process_all_suppliers transformation.
- Examine the processed_data_{today’s date}.txt file in the data/out folder and the log_{timestamp}.txt file in the logging folder.
Reference Links
Below are links to articles and videos about using the ETL Metadata Injection step in PDI.
Articles
The following articles provide more information about the ETL Metadata Injection step.
- "Metadata Injection – Examples for Special Scenarios" by Jens Bleuel
- "Metadata Driven ETL and Reporting with Pentaho Data Integration and Report Designer" by Diethard Steiner
- "Parse nasty XLS with dynamic ETL" by Matt Casters
- "Non-Native Metadata Injection" by Dan Keeley
Video
The following video provides more information about the ETL Metadata Injection step.