Customer Portal

Reformat - port redirection

Comments 2

  • Avatar
    smrckoval
    0
    Comment actions Permalink
    Hello,
    here is an example of such Reformat transformation based on graphOrdersTLReformat.grf SimpleExample. The records are sent to outputs according to the number of days between the order was exepted and shipped ( the output() function ). This transformation demonstrates what happens when the mapping for output 0 is definied explicitly while the others using .*.

    Output port 0 displays fields as defined in metadata and the Reformat transformation, while the other ports display only equally named fields, regardless upper/lower case, i.e., OrderID=ORDERID, CustomerID=CUSTOMERID.

    int key;
    int port;
    int temp;
    key=-1; // assign value to it
    function sum(a,b){
    return a+b;
    }
    function map0(){
    $0.*:= $0.*;
    }
    function map1(){
    $1.*:= $0.*;
    }
    function map2(){
    $2.*:= $0.*;
    }
    function output(ships){
    if (ships < 0 ) port=0;
    else if (ships < 30) port = 1;
    else port = 2;
    switch (port) {
    case 0:map0();
    case 1:map1();
    case 2:map2();
    }
    return port
    }
    // Transforms input record into output record.
    function transform() {
    temp = datediff($0.RequiredDate,$0.ShippedDate,day);
    $0.CUSTOMERID := $0.CustomerID;
    $0.PRODUCTID := ++key;
    $0.ORDERID := $0.OrderID;
    $0.CUSTOMER := join(';',$0.ShipName,$0.ShipAddress,$0.ShipCity,$0.ShipCountry);
    $0.SHIPTIME := temp;
    return output(temp)
    }
  • Avatar
    dpavlis
    0
    Comment actions Permalink
    Just a note,

    Such a thing (re-directing records to different output ports) should normally be done in Partition component - unless, of course, you want to do some data manipulation too.
    Partitioner also allows user specific partitioning function to be defined.

Please sign in to leave a comment.