Customer Portal

Normalized Data to Denormalized Number Columns - Use Denormalize Component?

Comments 2

  • Avatar
    svecp
    0
    Comment actions Permalink
    Well, this is fairly easily achievable by Denormalizer, as you suggested. If you can rely on number and structure of input records - which won't exceed projected output record's width and will have fields specified in correct order, you should be able to use following code (assuming all fields are strings, except ID).


    <output record's name> accumulator;
    integer cnt = 0; // How many records were processed in this group
    integer RECORD_OFFSET = 1; // How many fields should be skipped from reading of incoming record - skip just first field (ID)

    function integer append() {
    // Iteration number multiplied by number of fields to transfer (whole record, minus offset)
    integer outputOffset = cnt * (length($in.0) - RECORD_OFFSET);

    // Copy all fields from the record, disregard those at the beginning
    for (integer i=0;i<length($in.0)-RECORD_OFFSET;i++) {
    integer inFieldIdx = i+RECORD_OFFSET;
    integer outFieldIdx = outputOffset+i+RECORD_OFFSET;
    // Copy field of to an offset + current field position, skipping global offset (beginning of a record)
    // If there's anything to copy
    if (!isNull($in.0,inFieldIdx) {
    setStringValue(accumulator,outFieldIdx,getStringValue($in.0,inFieldIdx));
    }
    }

    // Increase iteration number
    cnt++;
    return OK;
    }

    // Copy accumulation record to the output and set ID of a group
    function integer transform() {
    $out.0.* = accumulator.*;
    $out.0.ID = $in.0.ID;
    return OK;
    }

    // Reset counter and accumulation record
    function void clean() {
    cnt = 0;
    resetRecord(accumulator);
    }


    There might be some errors in the code, haven't actually executed it. But the idea is to use CTL reflection and copy fields by order with given offset from "short" to "long" aggregated record.
  • Avatar
    hneff1
    0
    Comment actions Permalink
    Thank you Pavel! That worked perfectly! I just added one check to make sure the number of records in each group did not exceed the number I want to load which is 5.

    if ( cnt <= 4 ) {
    if (isNull($in.0,inFieldIdx) == false ) {
    setStringValue(accumulator,outFieldIdx,getStringValue($in.0,inFieldIdx));
    }
    }

    Thanks for your help and quick turnaround!

    Heather

Please sign in to leave a comment.