Informatica and Java
In this post I”ll be showing you how simple Java code may help us to implement loops, create rows, idle for some time between rows and more.
In first example we will generate rows by splitting string from source by some delimiter. For example we get three fields in Source (Id, Sentence, Delimiter) I would like to get as many rows as written in “Sentence” by some delimiter.
For this purpose we need to…
- Create Java Transformation
- To decide, it will be Active or Passive transformation. In this case, we affecting on all fields by generating additional rows (from single source row, might be created many rows in target) so we must use “Active” mode and pass through all fields from source. When you implementing only “Idle time” between rows, without any affect on other fields or generating rows, you may use “Passive” transformation.
Now we need to create new output port for getting result value. By using up/down rows we can assign ports to input or output groups.
Go to “Java Code” tab add your code, compile it and we’re done. ;-)
Just pay attention on naming convention, variable names in code must be exactly with same name as it mentioned in “Ports” tab.
By the way, we can easily count words we get in “sentence”. To do that, create additional output port in transformation, and add “your_port_name = words_array.length;” to java code. (Before or after “for” loop)
In next example I want my map to “sleep” for some time before processing next row. I would do that if I can call for some function or Web service only once per time period.
So here is a table values
As I have mentioned before, it may be “Passive” mode transformation, so my map is looks like this
Doing nothing but passing “Sleep Description” value to target.
Here is running time results
To achieve that, we need create Java Transformation with code below:
try {TimeUnit.SECONDS.sleep(Idle_Time_Sec);}
catch (InterruptedException e) {Error="Sleep Problem "+e.getMessage();}
Now, because of using "TimeUnit.SECONDS.sleep(Idle_Time_Sec);" we need to import some built-in java package by writing “import java.util.concurrent.TimeUnit;” in “Import Packages” Tab.
When your transformation is ready, compile it and you ready to go.
P.S. Don’t forget to compile your code each time you changing it. Session need to be refreshed after compilation.
Now you know a little bit more, hope it was helpful. ;-)
grate post. well done
It was not so long ago, but i still remember your first steps with Informatica . I'm more than proud of your achievements . I won't be surprised if i discover that you're much better than me now . Keep going !!!