Pentaho SDK,如何定义文本文件输入

时间:2015-11-30 17:24:11

标签: java pentaho pentaho-spoon

我正在尝试通过代码定义Pentaho Kettle(ktr)转换。我想在转换中添加一个文本文件输入步骤:http://wiki.pentaho.com/display/EAI/Text+File+Input

我不知道该怎么做(注意我想在自定义Java应用程序中实现结果,而不是使用标准的Spoon GUI)。我想我应该使用TextFileInputMeta类,但是当我尝试定义文件名时,trasformation不再起作用(在Spoon中似乎是空的)。

这是我正在使用的代码。我认为第三行出了点问题:

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

1 个答案:

答案 0 :(得分:3)

要以编程方式运行转换,您应该执行以下操作:

  1. Initialise Kettle
  2. 准备TransMeta对象
  3. 准备好您的步骤
    • 不要忘记Meta和Data对象!
  4. 将其添加到TransMeta
  5. 创建Trans并运行它
    • 默认情况下,每个转换每个步骤都会萌发一个线程,因此使用trans.waitUntilFinished()强制您的线程等待执行完成
  6. 必要时选择执行结果
  7. 使用此测试作为示例:https://github.com/pentaho/pentaho-kettle/blob/master/test/org/pentaho/di/trans/steps/textfileinput/TextFileInputTests.java

    另外,如果您的情况可以接受,我建议您手动创建转换并从文件中加载转换。这将有助于避免大量的样板代码。在这种情况下运行转换非常容易,请参阅此处的示例:https://github.com/pentaho/pentaho-kettle/blob/master/test/org/pentaho/di/TestUtilities.java#L346

相关问题