Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: LOOP Condition in PDI

  1. #1

    Default LOOP Condition in PDI

    Hello,


    I am having employee records. One Logical record (for one employee) is distributed in 4 lines. 1st character denotes record nature.
    1 - Employee Number
    2 - Employee Name
    3 - Designation
    L - Location


    Source Records:-
    17325
    2James
    3Clerk
    LNewyork
    17617
    2Scot
    3Manager
    14537
    2Ryan
    LLondon
    17628
    2Ritesh
    3Developer
    LMumbai
    Now I have to denormalize these logical records so that one one logical record will be in single line (not in 4 lines). For that purpose, I want to add a group field say "RecordGr".


    Output should be like:-
    17325;Record1
    2James;Record1
    3Clerk;Record1
    LNewyork;Record1
    17617;Record2
    2Scot;Record2
    3Manager;Record2
    14537;Record3
    2Ryan;Record3
    LLondon;Record3
    17628;Record4
    2Ritesh;Record4
    3Developer;Record4
    LMumbai;Record4
    Logic will be:-
    Increment RecordGr by 1 when it finds substr(source, 0, 1) = 1.
    1st line is compulsory for a logical record. Hence all the records will start with employee number.


    I am not able to increment RecordGr by 1 based on some condition. Though I find this logic very easy in plsql, I am not able to do it in PDI.
    Any help will be much apprecialted.


    Regards,
    Ritesh

  2. #2
    Join Date
    Nov 2008
    Posts
    777

    Default

    I would use a Javascript Step with code something like the following:

    Code:
    var counter;
    var RecordGr;
    
    if (counter == null) {
        counter = 0;
    }
     
    
    if (substr(Line, 0, 1) == "1") {
        counter++;
    }
    
    RecordGr = "Record" + str2num(counter);
    which should produce the output you desire:

    Name:  Untitled.jpg
Views: 62
Size:  20.7 KB
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

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.