Java Transformation Example
Java Transformation Example
Applies to:
Informatica PowerCenter
Summary
This article briefs about implementing FOR loop in Informatica using Java Transformation.
Author Bio
Author(s): Sukumar Balasubramanian Company: CIBC Created on: November 17, 2009 Sukumar Balasubramanian is an experienced Informatica ETL Consultant working with CIBC, Canada. He has good exposure to Data Integration/Data Warehousing Projects. He is also a key contributor in informatica-l group of ittoolbox .This is his first technical article in TechNet.
http://technet.informatica.com 1
Table of Contents
INTRODUCTION ................................................................................................................................................ 3 REQUIREMENT ................................................................................................................................................. 3 SOURCE ......................................................................................................................................................... 3 TARGET .......................................................................................................................................................... 3 SOLUTION OVERVIEW ..................................................................................................................................... 4 SOLUTION STEPS ............................................................................................................................................. 4 SOURCE ......................................................................................................................................................... 4 EXPRESSION TRANSFORMATION .............................................................................................................. 4 JAVA TRANSFORMATION ............................................................................................................................ 5 TARGET .......................................................................................................................................................... 6 OUTPUT ......................................................................................................................................................... 6 ADVANTAGES ................................................................................................................................................... 7 DISCLAIMER AND LIABILITY NOTICE ............................................................................................................. 8
http://technet.informatica.com 2
INTRODUCTION
This article briefs about implementing FOR loop in Informatica using Java Transformation.
REQUIREMENT
Consider that we are receiving a | delimited flat file that contains the sales persons tour information.
SOURCE
| | | | |
| | | | |
Our requirement is to generate Tour Table TARGET that contains the following
TARGET Salesperson Name Sukumar Sukumar Sukumar Sukumar Sukumar Sukumar Ram Ram Ram Ram Ram Ram Date 20091117 20091118 20091119 20091120 20091121 20091122 20091117 20091118 20091119 20091120 20091121 20091122 Place Chennai Chennai Chennai Bangalore Bangalore Bangalore Bangalore Bangalore Bangalore Chennai Chennai Chennai
http://technet.informatica.com 3
SOLUTION OVERVIEW
To achieve the above requirement we will be using the Java Transformation available in Informatica PowerCenter.
SOLUTION STEPS
SOURCE Delimited Flat File TourInfo.txt Salesperson Name Sukumar Ram Sukumar Ram | | | | | Tour from Date | 20091117 20091117 20091120 20091120 | | | | Tour to Date 20091119 20091119 20091122 20091122 | | | | | Place Chennai Bangalore Bangalore Chennai
EXPRESSION TRANSFORMATION
Type I O
Expression
Use the substring, instr function to retrieve the sales person name using the | delimiter. Use the substring, instr function to retrieve the From Date using the | delimiter. Use the substring, instr function to retrieve the To Date name using the | delimiter. Use the substring, instr function to retrieve the Place using the | delimiter. To_date(FromDate,YYYYMMDD) To_date(ToDate,YYYYMMDD)
FromDate
String(20)
ToDate
String(20)
Place
String(20)
FromDate_out ToDate_out
O O
Expression transformation is used for retrieving the values from the flat file source and assigns values to individual ports.
http://technet.informatica.com 4
JAVA TRANSFORMATION
Drag the java transformation into the Mapping. Create the following ports. Port Name Salesperson Name FromDate ToDate Place FromDate_out ToDate_out TourDate Data Type String(50) String(20) String(20) String(20) Date time Date time DateTime Type I/O I I I/O O O O
Link the FromDate_out, toDate_out from the Expression Transformation to the From Date and To Date ports of the Java transformation. Under the Java code tab; Import Package tab place the below code: Import java.util.*; Import java.text.*; This is to import relevant java packages. Under "On InputRow " tab place the following code
http://technet.informatica.com 5
The above code snippet uses the java calendar function. You can see for loop construction based on the from date and the to date, We need to link the salesperson name, Tour Date and Place ports from this java transformation to the target.
TARGET
OUTPUT
Target:
Java transformation takes the from date and to date as input and a FOR loop is constructed. For each input row based on the from date and to date java transformation will generate multiple rows. In our case for a single row in source we will be generating 3 rows in target.
http://technet.informatica.com 6
ADVANTAGES
Java transformation can be used to generate multiple rows based on a condition. Normalizer can generate rows based on the Occurs clause where we will specify a static number but if you want to generate multiple rows based on a dynamic value then go for java transformation.
http://technet.informatica.com 7
http://technet.informatica.com 8