Skip to main content

ROW

ROW( { fields } , recstruct )

ROW( row , resultrec )

ROW( [ row , ] transform )

fieldsA comma-delimited list of data values for each field in the recstruct, contained in curly braces ( {} ).
recstructThe name of the RECORD structure defining the field layout.
rowA single row of data. This may be an existing record, or formatted in-line data values like the fields parameter description above, or an empty set ( [ ] ) to add a cleared record in the format of the resultrec. If omitted, the record is produced by the transform function.
resultrecA RECORD structure that defines how to construct the row of data, similar to the type used by TABLE.
transformA TRANSFORM function that defines how to construct the row of data.
Return:ROW returns a single record.

The ROW function creates a single data record and is valid for use in any expression where a single record is valid.

ROW Form 1

The first form constructs a record from the in-line data in the fields, structured as defined by the recstruct. This is typically used within a TRANSFORM structure as the expression defining the output for a child dataset field.

Example:

AkaRec := {STRING20 forename,STRING20 surname};
outputRec := RECORD
  UNSIGNED id;
  DATASET(AkaRec) kids;
END;
inputRec := {UNSIGNED id,STRING20 forename,STRING20 surname};
inPeople := DATASET([{1,'Kevin','Halligan'},{1,'Kevin','Hall'},
                     {2,'Eliza','Hall'},{2,'Beth','Took'}],inputRec);
outputRec makeFatRecord(inputRec L) := TRANSFORM
  SELF.id := l.id;
  SELF.kids := DATASET([{ L.forename, L.surname }],AkaRec);
END;
fatIn := PROJECT(inPeople, makeFatRecord(LEFT));
outputRec makeChildren(outputRec L, outputRec R) := TRANSFORM
  SELF.id := L.id;
  SELF.kids := L.kids + ROW({R.kids[1].forename,R.kids[1].surname},AkaRec);
END;
r := ROLLUP(fatIn, id, makeChildren(LEFT, RIGHT));

ROW Form 2

The second form constructs a record from the row passed to it using the resultrec the same way the TABLE function operates. This is typically used within a TRANSFORM structure as the expression defining the output for a child dataset field.

Example:

AkaRec := {STRING20 forename,STRING20 surname};
outputRec := RECORD
UNSIGNED id;
DATASET(AkaRec) children;
END;
inputRec := {UNSIGNED id,STRING20 forename,STRING20 surname};
inPeople := DATASET([{1,'Kevin','Halligan'},{1,'Kevin','Hall'},
                     {1,'Gawain',''},{2,'Liz','Hall'},
                     {2,'Eliza','Hall'},{2,'Beth','Took'}],inputRec);
outputRec makeFatRecord(inputRec L) := TRANSFORM
  SELF.id := l.id;
  SELF.children := ROW(L, AkaRec); //using Form 2 here
END;
fatIn := PROJECT(inPeople, makeFatRecord(LEFT));
outputRec makeChildren(outputRec L, outputRec R) := TRANSFORM
  SELF.id := L.id;
  SELF.children := L.children + 
                   ROW({R.children[1].forename,R.children[1].surname},AkaRec);

END;
r := ROLLUP(fatIn, id, makeChildren(LEFT, RIGHT));

ROW Form 3

The third form uses a TRANSFORM function to produce its single record result. The transform function must take at least one parameter: a LEFT record, which must be in the same format as the input record. The format of the resulting record may be different from the input.

Example:

NameRec := RECORD
  STRING5 title;
  STRING20 fname;
  STRING20 mname;
  STRING20 lname;
  STRING5 name_suffix;
  STRING3 name_score;
END;

MyRecord := RECORD
  UNSIGNED id;
  STRING uncleanedName;
  NameRec Name;
END;

x := DATASET('RTTEST::RowFunctionData', MyRecord,THOR);
  

STRING73 CleanPerson73(STRING inputName) := FUNCTION
  suffix:=[ ' 0',' 1',' 2',' 3',' 4',' 5',' 6',' 7',' 8',' 9',
            ' J',' JR',' S',' SR'];
  InWords := Std.Str.CleanSpaces(inputName);
  HasSuffix := InWords[LENGTH(TRIM(InWords))-1 ..] IN suffix;
  WordCount := LENGTH(TRIM(InWords,LEFT,RIGHT)) - LENGTH(TRIM(InWords,ALL))+1;
  HasMiddle := WordCount = 5 OR (WordCount = 4 AND NOT HasSuffix) ;
  Space1 := Std.Str.Find(InWords,' ',1);
  Space2 := Std.Str.Find(InWords,' ',2);
  Space3 := Std.Str.Find(InWords,' ',3);
  Space4 := Std.Str.Find(InWords,' ',4);
  STRING5 title := InWords[1..Space1-1];
  STRING20 fname := InWords[Space1+1..Space2-1];
  STRING20 mname := IF(HasMiddle,InWords[Space2+1..Space3-1],'');
  STRING20 lname := MAP(HasMiddle AND NOT HasSuffix =>
                         InWords[Space3+1..],
                        HasMiddle AND HasSuffix =>
                         InWords[Space3+1..Space4-1],
                        NOT HasMiddle AND NOT HasSuffix =>
                         InWords[Space2+1..],
                        NOT HasMiddle AND HasSuffix =>
                         InWords[Space2+1..Space3-1],
                        '');
  STRING5 name_suffix := IF(HasSuffix,InWords[LENGTH(TRIM(InWords))-1 ..],'');
  STRING3 name_score := '';
  RETURN title + fname + mname + lname + name_suffix + name_score;
END;

//Example 1 - a transform to create a row from an uncleaned name
NameRec createRow(string inputName) := TRANSFORM
  cleanedText := CleanPerson73(inputName);
  SELF.title := cleanedText[1..5];
  SELF.fname := cleanedText[6..25];
  SELF.mname := cleanedText[26..45];
  SELF.lname := cleanedText[46..65];
  SELF.name_suffix := cleanedText[66..70];
  SELF.name_score := cleanedText[71..73];
END;

myRecord t(myRecord L) := TRANSFORM
  SELF.Name := ROW(createRow(L.uncleanedName));
  SELF := L;
END;
y := PROJECT(x, t(LEFT));
OUTPUT(y);

//Example 2 - an attribute using that transform to generate the row.

NameRec cleanedName(STRING inputName) := ROW(createRow(inputName));
myRecord t2(myRecord L) := TRANSFORM
  SELF.Name := cleanedName(L.uncleanedName);
  SELF := L;
END;
y2 := PROJECT(x, t2(LEFT));
OUTPUT(y2);

//Example 3 = Encapsulate the transform inside the attribute by
// defining a FUNCTION structure.
NameRec cleanedName2(STRING inputName) := FUNCTION

  NameRec createRow := TRANSFORM
    cleanedText := CleanPerson73(inputName); 
    SELF.title := cleanedText[1..5];
    SELF.fname := cleanedText[6..25];
    SELF.mname := cleanedText[26..45];
    SELF.lname := cleanedText[46..65];
    SELF.name_suffix := cleanedText[66..70];
    SELF.name_score := cleanedText[71..73];
  END;

  RETURN ROW(createRow); //omitted row parameter
END;

myRecord t3(myRecord L) := TRANSFORM
  SELF.Name := cleanedName2(L.uncleanedName);
  SELF := L;
END;

y3 := PROJECT(x, t3(LEFT));

OUTPUT(y3);

See Also: TRANSFORM Structure, DATASET, RECORD Structure, FUNCTION Structure