Question

I am facing an issue related to olap and kettle. Thing is I am using pentaho DI(kettle) to export data from my database to olap star schema(facts & dimensions). Now when it comes to timestamp I am able to retreive months,years and days from aw timestamp using calculator in kettle . Now What I need is to convert month numeric value to its coresponding month name (like replace 1 with JAN and so on). How this can be acheived with kettle . Please suggest me .

Was it helpful?

Solution

In PDI/Kettle, I've found it tricky to set the value of one field based on the value of another field that is a different data type. A JavaScript or Formula step will do it, but in this case I think I'd use a Stream Lookup because your lookup values are few and fixed.

Use a Data Grid step with an Integer column for the month number (1, 2, 3 ...) and a string column with the month name (JAN, FEB, MAR ...). Use this step as the 'Lookup step' in your Stream Lookup. Then just retrieve the month name into your data flow. This should be pretty fast, which is good if you're working with typical data warehouse volumes.

OTHER TIPS

As Brian said you can also use the Modified JavaScript step to perform the conversion. Here is how you can do it with that:

var month_names=new Array();
month_names[1]="Jan";
month_names[2]="Feb";
month_names[3]="Mar";
month_names[4]="Apr";
month_names[5]="May";
month_names[6]="Jun";
month_names[7]="Jul";
month_names[8]="Aug";
month_names[9]="Sep";
month_names[10]="Oct";
month_names[11]="Nov";
month_names[12]="Dec";
var month_short = month_names[month_num];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top