RSS

Tag Archives: informatica

Informatica Java Transform handling of Dates

I love working with the java transform in informatica because it gives me all the freedom in the world, and it makes my mappings compact, rather than having tens of drag and dropped components. I can usually achieve a lot with only one java transform.

One thing confounded me recently as I could not from in side a java transform assign a date value to an output port I had defined as a date/time port.
So the code below could not work.
date_port_out = New Date();

I tried a bunch of alternatives , example using simpleDateFormat to create a format that is the default in informatica, but nothing was working.
Then I decided to look at the generated code in the java transform

informatica_date_in_java

I couldn’t believe it ; When I create a date/time port, the java transform creates a long out of it. How does it do this, I could guess , but I sure know how to convert a java Date into the millisecond values since epoch (Jan 1st 1970).

long millis_since_epoch = new Date().getTime();

Then I assigned the long value to the output port – and it worked !!

date_port_out = new Date().getTime; 

Also important not to forget to import the Date package in the imports tab;

import java.util.Date;
 
Leave a comment

Posted by on July 29, 2015 in programming, software

 

Tags: , , , ,

Informatica Java Transform For Data Validation

I have been working in informatica for a while now, and every time I need to do something thats out of the ordinary filter, sort , run a query, aggregate, I usually resort to the swiss army knife that is the java transform.

One of the  main abilities I get from the java transform is the creation new rows of output from a single row of input. Why would I want to do this? Well one common use case I have seen examples of out there is to unpivot your data transpose columns into rows.

So If you have data like

Hubert_Blaine_Wolfeschlegelsteinhausenbergerdorff Mary
10 20

And you need it to look more like

Hubert_Blaine_Wolfeschlegelsteinhausenbergerdorff 10
Mary 20

All nice and dandy. But I had another use case that I think is more interesting.

I have a set of data I need to validate for errors, and for each row, there are several errors that could occur. So one row could have 10 errors spread out in different columns.

I needed a process that goes through my set of data and creates another set of data holding the collection of validation errors.

So for example, I have the following row, and 2 errors I need to create from this: The names should be less than 20 characters , and the number (lets assume its the age) should be greater than 18

Hubert_Blaine_Wolfeschlegelsteinhausenbergerdorff 10

And I need the outputs

The name “Hubert_Blaine_Wolfeschlegelsteinhausenbergerdorff” is longer than 20 characters
The age 10 is less than 18

They way to achieve this was to use an active java transform (emphasize ‘active’) in which I have logic like below:

if(NAME.length > 20) {
error_port_out = "The name "+ name_port_in+ " is longer than 20 characters";
generateRow(); //does the magic of adding additional output rows from one input row
}

if(age > 18) {
error_port_out = "The age"+ age_port_in+ " is less than 18";
generateRow(); //again
}
 
Leave a comment

Posted by on July 29, 2015 in software

 

Tags: , , , ,