Search code examples
pentahoetlkettlespoonpdi

Pentaho ETL : Modified Javascript Step "SKIP_TRANSFORMATION" transformation Constant work logic


Why the SKIP_TRANSFORMATION works only when the CONTINUE_TRANSFORMATION assigned to trans_Status? I am not able to find information regarding this, in the wiki link

//Not working (not getting skipped)
if (sequence_value%2==0){
    trans_Status = SKIP_TRANSFORMATION;
}

//Working (checked from an online example)
trans_Status = CONTINUE_TRANSFORMATION;
if (sequence_value%2==0){
    trans_Status = SKIP_TRANSFORMATION;
}

Thanks in advance.


Solution

  • trans_Status=CONTINUE_TRANSFORMATION;
    

    What it does is, it reads all the incoming rows and processes it and move it to the next step. Its by default.

    trans_Status=SKIP_TRANSFORMATION;
    

    It reads the data from the processed rows and rejects it.

    But the case becomes different in case of filtering out the results (as in your question). In order to filter or reject rows based on certain condition, trans_Status should have a copy of all the processed rows first. Once it is available in the variable, SKIP_TRANSFORMATION based on the condition will reject/filter the condition. This is basically the reason for the scenarios in the question. In your case (without using the CONTINUE_TRANSFORMATION), the trans_Status is not finding any stored/processed variable to apply the condition.

    The best way to understand (i assume) is to use the below snip in the JS step:

    if(field == "BB"){      //condition to filter the rows          
         trans_Status=SKIP_TRANSFORMATION;     //filter rows on condition
    }
    Alert(field);
    

    Here, field is the data field coming from the previous step/source. Take some 5-10 data, just for POC.

    Once you preview the JS script, you will find that initially all the source values (fields column) will be alerted. But Once all the rows are preview or processed, then the SKIP_TRANSFORMATION will work and rejects all the rows, eventually giving you all the rejected rows.

    So, concluding, if you are having any condition applied in JS and you want to use these CONSTANTS. You might need to ensure that all the rows are processed and stored into the trans_Status variable first (best way is to use CONTINUE_TRANSFORMATION) and then place all the condition.


    You can also read my blog on the same.

    Hope this explanation helps and hoping i am correct :)