0

I'm trying to define a Pentaho Kettle (ktr) transformation via code. I would like to add to the transformation a Text File Input Step: http://wiki.pentaho.com/display/EAI/Text+File+Input.

I don't know how to do this (note that I want to achieve the result in a custom Java application, not using the standard Spoon GUI). I think I should use the TextFileInputMeta class, but when I try to define the filename the trasformation doesn't work anymore (it seems empty in Spoon).

This is the code I'm using. I think the third line has something wrong:

PluginRegistry registry = PluginRegistry.getInstance();
TextFileInputMeta fileInMeta = new TextFileInputMeta();
fileInMeta.setFileName(new String[] {myFileName});
String fileInPluginId = registry.getPluginId(StepPluginType.class, fileInMeta); 
StepMeta fileInStepMeta = new StepMeta(fileInPluginId, myStepName, fileInMeta);
fileInStepMeta.setDraw(true);
fileInStepMeta.setLocation(100, 200);
transAWMMeta.addStep(fileInStepMeta);           
ufo
  • 674
  • 2
  • 12
  • 35

1 Answers1

3

To run a transformation programmatically, you should do the following:

  1. Initialise Kettle
  2. Prepare a TransMeta object
  3. Prepare your steps
    • Don't forget about Meta and Data objects!
  4. Add them to TransMeta
  5. Create Trans and run it
    • By default, each transformation germinates a thread per step, so use trans.waitUntilFinished() to force your thread to wait until execution completes
  6. Pick execution's results if necessary

Use this test as example: https://github.com/pentaho/pentaho-kettle/blob/master/test/org/pentaho/di/trans/steps/textfileinput/TextFileInputTests.java

Also, I would recommend you create the transformation manually and to load it from file, if it is acceptable for your circumstances. This will help to avoid lots of boilerplate code. It is quite easy to run transformations in this case, see an example here: https://github.com/pentaho/pentaho-kettle/blob/master/test/org/pentaho/di/TestUtilities.java#L346

  • Thank you. Unfortunately I cannot load the trasformation from file, I have to create it from scratch. The code you posted about "TextFileInputMeta" gives me warnings about deprecated classes (like "TextFileInputField") and I don't know how to solve. Anyway, now I'm using the "CsvInputMeta". It works better. But I should load the fields in a manner similar to the "Get fields" button in Spoon. How can I obtain this? – ufo Dec 01 '15 at 16:54
  • @ufo, in 6.0, TextFileInput step was deprecated, and a brand new (refactored) is recommended - https://github.com/pentaho/pentaho-kettle/blob/master/engine/src/org/pentaho/di/trans/steps/fileinput/text/TextFileInput.java . If you post here your code, I can try to help you. W/o seeing where is your troubles it is really hard to guess :) – Andrey Khayrutdinov Dec 04 '15 at 07:10