PDI插件,getInputRowMeta()抛出非指针异常

时间:2015-08-05 18:32:20

标签: pentaho kettle pdi

在我的插件中,我尝试从上一步获取MetaData信息,以便我可以根据它的元数据信息(列名)对行数据进行一些处理。

根据数据工作正常,因为r = getRow(),可以获取数据。但是当调用getInputRowMeta()来获取前一步的行元时,它会抛出非指针异常。

代码示例如下(主要是processRow()函数。)

    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {

    meta = (NAAClientStepMeta) smi;
    data = (NAAClientStepData) sdi;

    option = meta.getOption();
    message = option;
    if (first) {
        first = false;
        if(option.equals("Publisher AccountIDs")){
            getInputRowMeta().size(); // don't work here, throw exception.
            RowMetaInterface rm = (RowMetaInterface) getInputRowMeta().clone();
            data.outputRowMeta = rm;
            meta.getFields(rm, getStepname(), null, null, this);
            //String previousSteps[] = transMeta.getPrevStepNames("New Acquisio API Client");
            //RowSet rowSet = this.findOutputRowSet(transMe);
            //RowMetaInterface rowMeta = rowSet.getRowMeta();
            r = getRow();

调用getInputRowMeta()时,它会抛出异常,如下所示:

2015/08/05 14:11:00 - New Acquisio API Client 2.0 - ERROR (version 4.4.0 stable, build 17588 from 2012-11-21 16.02.21 by buildguy) : Unexpected error
2015/08/05 14:11:00 - New Acquisio API Client 2.0 - ERROR (version 4.4.0-stable, build 17588 from 2012-11-21 16.02.21 by buildguy) : java.lang.NullPointerException
2015/08/05 14:11:00 - New Acquisio API Client 2.0 - ERROR (version 4.4.0-stable, build 17588 from 2012-11-21 16.02.21 by buildguy) :    at com.acquisio.kettle.plugins.NAAClientStep.processRow(NAAClientStep.java:183)
2015/08/05 14:11:00 - New Acquisio API Client 2.0 - ERROR (version 4.4.0-stable, build 17588 from 2012-11-21 16.02.21 by buildguy) :    at org.pentaho.di.trans.step.RunThread.run(RunThread.java:50)
2015/08/05 14:11:00 - New Acquisio API Client 2.0 - ERROR (version 4.4.0-stable, build 17588 from 2012-11-21 16.02.21 by buildguy) :    at java.lang.Thread.run(Thread.java:745)

是否有任何地方StepMeta类,我应该设置StepData类?

1 个答案:

答案 0 :(得分:1)

这绝对是对的。底层PDI类不知道输入流的元数据UNTIL它已读取第一行。所以你的r = getRow()必须提前。构建UDJC步骤时常见的事情!