Using PowerCenter to Process Flat Files in Real Time

Using PowerCenter to Process Flat Files in Real Time

Configuring the Java Transformation

Configuring the Java Transformation

Configure the Java transformation to receive the file path and delimiter as input and then read the file.
You can import the Java transformation from the following location: https://docs.informatica.com/content/dam/source/resources/zipfiles/0441_ReadFF.zip .
  1. Download
    super-csv-distribution-2.0.0-bin.zip
    from the following location: http://sourceforge.net/projects/supercsv/.
    The Super CSV materials at the identified URL are open source materials and are being referenced as example material. Informatica is not endorsing these materials and is not responsible for the performance of or the risks posed by such materials.
  2. Extract the ZIP file and then find the following JAR files in the extracted
    super-csv
    folder:
    • super-csv-2.0.0.jar
    • super-csv-2.0.0-javadoc.jar
    • super-csv-2.0.0-sources.jar
  3. Copy the JAR files to
    <Informatica Installation Directory>\server\bin\javalib
    .
  4. In the Designer, add a Java transformation to the mapping as an active transformation.
  5. Open the Java transformation.
  6. On the
    Ports
    tab, create the following input ports:
    Port Name
    Datatype
    Precision
    FilePath
    string
    1000
    Delimiter
    string
    10
  7. Create a string output port for each field in the flat file source.
    The following figure shows the completed
    Ports
    tab for a flat file that contains three fields:
    The transformation has a string input port named FilePath and another string input port named Delimiter. The transformation has three string output ports named CSVField1, CSVField2, and CSVField3.
  8. On the
    Properties
    tab, set
    Transformation Scope
    to
    Transaction
    .
  9. On the
    Java Code
    tab, click
    Settings
    .
  10. In the
    Settings
    dialog box, click
    Browse
    under
    Add Classpath
    to select the Super CSV jar files that you downloaded and copied to
    <Informatica Installation Directory>\server\bin\javalib
    .
  11. On the
    Import Packages
    code entry tab, enter the following code to import the required Java and third-party packages:
    import java.io.FileReader; import java.util.List; import org.supercsv.cellprocessor.Optional; import org.supercsv.cellprocessor.ParseBool; import org.supercsv.cellprocessor.ParseDate; import org.supercsv.cellprocessor.ParseInt; import org.supercsv.cellprocessor.constraint.*; import org.supercsv.cellprocessor.ift.CellProcessor; import org.supercsv.io.CsvListReader; import org.supercsv.io.ICsvListReader; import org.supercsv.prefs.CsvPreference;
  12. On the
    On Input Row
    code entry tab, enter the following Java code:
    ICsvListReader listReader = null; try{ final CsvPreference CUSTOM_DELIMITED = new CsvPreference.Builder('"',Delimiter.charAt(0), "\n").build(); listReader = new CsvListReader(new FileReader(FilePath), CUSTOM_DELIMITED); //listReader.getHeader(false); // skip the header (can't be used with CsvListReader) List<String> customerList; int numCols=grp.getOutputFieldList().size(); while( (customerList = listReader.read()) != null ) { for(int i=1;i<=numCols;i++){ if(i<=listReader.length()&&listReader.get(i)!=null) outputBuf.setString(outRowNum, i-1, listReader.get(i)); else outputBuf.setNull(outRowNum, i-1); } incrementOutputRowNumber(); flushBufWhenFull(); clearNullColSet(); } }catch(Exception e){ failSession("Could not read or open the specified file. Or, port could not hold the data. Check the size of the port or the specified delimiter."); }
  13. Click
    Compile
    to compile the Java code for the transformation.
  14. Click
    OK
    .
  15. Link the following ports from the JMS Application Source Qualifier transformation to the Java transformation:
    JMS Application Source Qualifier Transformation Output Port
    Java Transformation Input Port
    BodyText
    FilePath
    FlatFileDelimiter
    Delimiter

0 COMMENTS

We’d like to hear from you!