ufo
ufo

Reputation: 685

Pentaho SDK, how to define a text file input

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);           

Upvotes: 0

Views: 442

Answers (1)

Andrey Khayrutdinov
Andrey Khayrutdinov

Reputation: 176

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

Upvotes: 3

Related Questions