Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: UDJC Step terminates when outputting multiple output rows per single input row

  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Default UDJC Step terminates when outputting multiple output rows per single input row

    I'm a newbie to using Kettle and I use PDI CE 4.0.1

    I haev a simple requirement to convert a input text file w/ JSON array to output a text file w/ each line containing an element in the JSON array.

    E.g:
    Input: {ITEMS:[{ID:1,NAME:A},{ID:2,NAME:B}]}
    OUTPUT:
    1, A
    2, B

    My transformations look like this
    Text File Input -> Mod javascript Value > User Defined Java Class (UDJC) -> Text File output

    I use Mod javascript value to parse the JSON values and then pass it to UDJC to output multiple rows per single input row,

    // code fragment to output multple rows

    for(int i=0; i < idArr.length;i++) {
    Object[] clonedRow = getInputRowMeta().cloneRow(r);
    clonedRow = createOutputRow(clonedRow, clonedRow.length);
    ....
    putRow(data.outputRowMeta, clonedRow);
    }

    When I run the transformation, the UDJC and text file output stops prematurely and the first 2 steps (text file input and Mod JS value) is still executing and nothing happens. I get a partial output with correct output data!

    Any thoughts or ideas?

    Thanks in advance!

  2. #2

    Default

    If you plan on parsing multiple input rows, make sure you have something similar a the begining:

    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
    {
    Object[] r = getRow();

    if (r == null) {
    setOutputDone();
    return false;
    }

    ... (your code)

    return true;
    }

    The return false, tells the step to stop processing rows...

    And at the end of the class, the return true, will assume more rows are coming. I am far from an expert in this, but I had a problem similar to you, and I solved it by doing the above.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.