Customer Portal

Comments 6

  • Avatar
    twaller
    0
    Comment actions Permalink
    Hello Mike,

    Yes, it is possible. To learn how to do it, look at the following site:
    http://wiki.cloveretl.org/doku.php?id=m ... toclover26

    Best regards,

    Tomas Waller
  • Avatar
    twaller
    0
    Comment actions Permalink
    Oh, maybe I did not understand you well.
    If you want to split one record into more records, in other words, send some fields to some output port, other fields to another, etc., you should use Normalizer.
    Normalizer is described here:
    http://www.cloveretl.com/_upload/clover ... l#d0e18904
    and here:
    http://wiki.cloveretl.org/doku.php?id=c ... ansformers
    If you want to write transformation in Java, you can also use the link mentioned in my previous reply.

    Best regards,

    Tomas Waller
  • Avatar
    twaller
    0
    Comment actions Permalink
    Our SimpleExamples project also includes two examples that use Normalizer:
    graphNormalizeInline.grf (transformation is written in Java)
    graphNormalizeTL.grf (transformation is written in Clover Transformation Language).
  • Avatar
    mike
    0
    Comment actions Permalink
    Hi,

    Sorry. I think I didnt explain myself very well. :-(

    I would like to turn this record from Input Port 0

    ID|FirstName|LastName|Colour1|Colour2
    1|Mike|Johnson|Red|Blue


    into Output Port 0
    ID|FirstName|LastName|Colour
    Record 1 : 1|Mike|Johnson|Red
    Record 2 : 1|Mike|Johnson|Blue


    Still using one input and one output... but making multiple records on one output.

    M
  • Avatar
    twaller
    0
    Comment actions Permalink
    Hello Mike,

    I am not the right Java man. (But I will ask my "Java" colleagues to reply you.)

    But anyway, should you write your transformation in CTL instead of Java, you could use the following code in Normalizer component:

    //#TL

    // This transformation defines the way in which one input record is normalized
    // into multiple output records.

    list colour;

    // This function returns the number of output records created for each input record. You either know how many records will be created or you need to count their number.
    function count() {
    push(colour,$0.Colour1);
    push(colour,$0.Colour2);
    return 2;
    }

    // This function creates the output records. It is called count() times for each
    // input record. The idx parameter specifies which output record is created, its
    // values range from 0 to count() - 1.
    function transform(idx) {
    $0.ID := $0.ID;
    $0.FirstName := $0.FirstName;
    $0.LastName := $0.LastName;
    $0.Colour := colour[idx];
    }

    // Called after each group of count() records. Between parsing of each pair of input records, the "colour" list must be cleaned.
    function clean() {
    remove_all(colour);
    }


    So, I will ask my colleagues and they will answer you question concerning Java.

    Best regards,

    Tomas Waller
  • Avatar
    avackova
    0
    Comment actions Permalink
    Hello Mike,
    see following java class as an example:
    import org.jetel.component.normalize.DataRecordNormalize;
    import org.jetel.data.DataRecord;
    import org.jetel.exception.TransformException;


    public class Colours extends DataRecordNormalize {

    public int count(DataRecord arg0) {
    return 2;
    }

    public int transform(DataRecord arg0, DataRecord arg1, int arg2)
    throws TransformException {
    arg1.getField(0).setValue(arg0.getField(0));
    arg1.getField(1).setValue(arg0.getField(1));
    arg1.getField(2).setValue(arg0.getField(2));
    arg1.getField(3).setValue(arg0.getField(3 + arg2));
    return OK;
    }

    }

Please sign in to leave a comment.