Professional Documents
Culture Documents
Java Transformation: Using Java Code To Parse A Flat File: © 2008 Informatica Corporation
Java Transformation: Using Java Code To Parse A Flat File: © 2008 Informatica Corporation
Overview
The Java transformation provides a simple native programming interface to define transformation functionality with the Java programming language. You can use the Java transformation to quickly define simple or moderately complex transformation functionality without advanced knowledge of the Java programming language or an external Java development environment. Create Java transformations by writing Java code snippets that define transformation logic. You can use Java code in a Java Transformation to parse and extract specific columns of data from a flat file. When the rows in each version of source flat file are of varying length, use the Java Transformation to read the flat file as a string. If you use the Java transformation to read the flat file as a string, you do not need to update the mapping for each flat file source of varying row length.
Example
In the following example, you use Java code to extract specific columns of data from a flat file of varying schema or a JMS message. You want to read the first two columns of data from a delimited flat file. Create a mapping that reads data from a delimited flat file and passes data to one or more output ports. The following figure shows how the Java transformation reads rows of data and passes data to a target:
The mapping contains the following components: y y y Source Definition and Source Qualifier Java Transformation Target Definition
Java Transformation
Use the Java transformation to read each row of data from a string and pass the data to output ports. Then, define the Java transformation functionality on the Java Code tab. The Java transformation has the following ports:
Name row f1 f11 Datatype String String String Type Input Output Output
On Input Row tab You can use the On Input Row tab to define transformation behavior when it receives an input row. Use the On Input Row tab of the Java Code tab to read each row of data from a string and pass the data to output ports. Enter the following code on the On Input Row tab to retrieve the first two columns of data:
StringTokenizer st1 = new StringTokenizer(row,","); // Reads each row of string data using the comma as the delimiter. f1 = st1.nextToken(); // Read the first column f11= st1.nextToken(); // Read the second column
The StringTokenizer reads each row of string data using the comma as the delimiter.
Target Definition
Configure the target to receive rows of data from the Java Transformation. After you run a workflow that contains the mapping, the target contains two columns of data. The target file has the following data: 1a,2a 1b,2b 1c,2c 1d,2d
Author
Padma Heid, Technical Writer