PDA

View Full Version : Re-Introducing UDJC



MattCasters
01-27-2010, 09:40 PM
Dear Kettle fans,

Daniel (http://daniele.livejournal.com/) & I had a lot of fun in Orlando last week. Among other things we worked on the User Defined Java Class (UDJC) step. If you have a bit of Java Experience, this step allows you to quickly write your own plugin in a step. This step is available in recent builds of Pentaho Data Integration (Kettle) version 4.

Now, how does this work? Well, let’s take Roland Bouman (http://rpbouman.blogspot.com/)’s example : the calculation of the the date of Easter (http://rpbouman.blogspot.com/2010/01/easter-eggs-for-mysql-and-kettle.html). In this blog post, Roland explains how to calculate Easter in MySQL and Kettle using JavaScript. OK, so what if you want this calculation to be really fast in Kettle? Well, then you can turn to pure Java to do the job…

<blockquote> import java.util.*; private int yearIndex; private Calendar calendar; public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { Object[] r=getRow(); if (r==null) { setOutputDone(); return false; } if (first) { yearIndex = getInputRowMeta().indexOfValue(getParameter("YEAR")); if (yearIndex