Using The SQL Transformation in An Informatica Developer Mapping
Using The SQL Transformation in An Informatica Developer Mapping
Developer Mapping
© 2010 Informatica
Abstract
You can run SQL queries against a relational database midstream in a mapping. This article describes how to configure an
SQL transformation in a logical data object mapping in the Developer tool.
Supported Versions
¨ Informatica 9.0.1
Table of Contents
Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Input Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Define the Input Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Logical Data Object Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Logical Data Object Mapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
SQL Transformation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Advanced Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Ports. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
SQL Query. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Run-time Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Filter Transformation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Running the Mapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Deploy the Mapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Overview
Your organization receives orders and customer information from multiple sources. The order numbers from one source are
alphanumeric. The orders from another source are numeric. You need to combine the orders into one format and generate a
company order number for each order.
This article explains how to create a logical data object model to represent a single view of the customer data and the order
data. The Order logical data object in the model defines the format of the order numbers. The article also explains how to
configure an SQL transformation to generate an order number for each order row in the logical data object mapping.
2
Input Files
The input files are flat file order files from different affilates. The content is similar, but the order numbers for one affiliate are
alphanumeric. The order numbers from the other affiliate are numeric.
A00005 333 910 Castle Hill Fort Collins CO 23.50 555577 Door_Handle
100000000 123456789 Window Cleaner 100 252 Handy Drive Foster City Ca 5.95
100000001 233334545 Octane Booster 121 16 Rut Street Redwood City Ca 3.95
100000002 333333567 Rug Shampoo 155 87 Oliver Street San Mateo Ca 4.95
100000003 222222456 Oil 183 566 Pamela Lane Las Vegas Ca 3.95
100000005 111115678 Tire Pump 444 212 Corolla Store Kimmel Or 49.99
100000006 444455566 Floor Mat 222 902 Valencia St San Francisco Ca 39.99
100000007 123456789 Window Cleaner 222 902 Valencia St San Francisco Ca 5.95
3
Define the Input Files
Create physical data objects to define the input files and define the path to each file. Define a location that the Data
Integration Service can access.
The following figure shows the physical data object in the workspace and the run-time properties for Affiliate A order file:
Configure the source file name and source file path in the run-time properties. To access run-time properties, click the
Output transformation and click the Runtime tab in the Properties view.
4
For this example, import the logical data object model from Order_Customer.xsd:
5
Logical Data Object Mapping
The logical data object mapping describes how you access data through a logical data object. A data object mapping might
contain transformations that cleanse or change the data.
For this example, create a logical data object mapping to map the orders from multiple sources to the Order logical data object.
1. Right-click the Order logical data object in the Navigator. Choose Map Logical Data Object.
The New Data Object Mapping dialog box appears.
2. Choose the Read Type.
3. Enter a name for the mapping.
The following figure shows a logical data object mapping that creates a single view of the orders:
ReadOrders_Affiliate_A
The input file of orders from affiliate A.
ReadOrders_Affiliate_B
The input file of orders from affiliate B.
Orders_Union
Union transformation that combines the rows from the input files. The Union transformation returns an alpha
numeric order number for all orders.
Orders_SQL
SQL transformation that assigns an order number to each row and increments a sequence number in a relational
table.
Filter
Filter transformation that filters rows that have NULL order numbers from the mapping.
6
SQL_Errors_File
Flat file that receives the original customer order number and the SQL error messages that the database might
return. The SQL_Errors file has the following structure:
The SQL_Errors file receives two rows for each order because the SQL transformation returns a row for each SQL
statement. Each row contains NULL in the SQL_Error column unless the database returns an error message for
the SQL statement.
Order
Logical data object that contains the single view of the customer orders. Order receives one row for each order.
SQL Transformation
The SQL transformation processes two SQL statements midstream in the mapping. The transformation retrieves a
sequence number from a table and returns it in an output port. The SQL transformation increments the sequence number in
the database table.
The Sequence_Number table contains the sequence number that the Data Integration Service applies to each customer
order. The Sequence_Number table is in an Oracle database. The sequence number becomes the company order number
in the logical data object.
¨ Advanced Properties. Configure the database type. The column datatypes depend on what database type you
choose.
¨ Ports. Define the pass-through ports and the output port that receives the order number from the
Sequence_Number table.
¨ SQL. Define the SQL query to retrieve the sequence number and to increment the number in the database table.
¨ Runtime. Choose a connection to the database that contains the sequence numbers.
Advanced Properties
When you configure advanced properties, the Developer tool changes the ports or port datatypes in the SQL transformation.
Configure advanced properties before you configure the ports.
Configure the following properties in the Advanced tab of the Orders_SQL transformation:
Database type
The database type is Oracle. When you define ports, you can choose port datatypes that are applicable for Oracle.
7
Query
The Advanced Properties view shows the SQL query that you define in the SQL Editor. Define the query in the
SQL view instead of the Advanced Properties view.
Note: The Connection Type and SQL Mode properties are read-only. The connection type is static. The SQL transformation
connects one time to the database with the connection object that you configure in the SQL transformation run-time
properties. The SQL Mode is query. The SQL transformation runs a query that you define in the transformation.
Ports
The output port returns the value from the SQL query. The pass-through ports pass the data in the input row through the
transformation. The SQL transformation does not change the data in pass-through ports.
All of the ports are pass-through ports except the SQLError and Sequence_No output ports.
When you create the SQL transformation, the Developer tool creates the SQLError port. The SQLError port returns SQL
errors from the database. You cannot delete this port.
The Sequence_No output port returns the sequence number value from the Sequence_Number table.
When you configure a query SELECT clause, the number and the order of the output ports must match the number and
order of the fields in the SELECT clause. The native type for the port must match the datatype of the column in the database.
When the number of output ports is more than the number of columns in the SELECT clause, the extra ports receive a NULL
value. When the number of output ports is less than the number of columns in the SELECT clause, the Data Integration
Service generates a row error.
To create a pass-through port, drag the ports from the Union transformation to the SQL transformation. In the Ports view,
select Copy to Output. The Developer tool creates the output ports and adds the suffix "_output" to each port name.
SQL Query
Access the SQL Editor in the SQL view.
The following figure shows rows that the SQL transformation generates:
8
The SQL transformation returns two rows for each input row. The transformation returns one row for the SELECT statement
and another row for the UPDATE statement in the query.
When a query contains a SELECT clause, the SQL transformation returns the data in the output ports, the pass-through
ports, and the SQLError port.
When a query contains an UPDATE clause, the query returns no data from the database. The SQL transformation returns
data to the SQLError port and the pass-through ports. Output ports return NULL values.
Run-time Properties
Choose a database connection in the Runtime view.
The SQL transformation connects to the database with the database connection object that you choose. The database type
in the connection must be the same database type that you configure in the Advanced Properties view.
Filter Transformation
The Filter transformation removes the rows that contain NULL sequence numbers.
The Filter transformation has the following expression in the Filter view:
SEQUENCE_NO > 0
The Filter transformation returns one row for each order. Each row has a unique sequence number. The sequence number
becomes the company order number in the logical data object.
9
The sequence number becomes the company order number in the logical data object.
Author
Ellen Chandler
Principal Technical Writer
10