PROJECT( recordset, transform [, PREFETCH [ (lookahead [, PARALLEL]) ] ] [, KEYED ] [, LOCAL ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )
PROJECT( recordset, record [, PREFETCH [ (lookahead [, PARALLEL]) ] ] [, KEYED ] [, LOCAL ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )
The PROJECT function processes through all records in the recordset performing the transform function on each record in turn.
The PROJECT(recordset,record) form is simply a shorthand synonym for:
PROJECT(recordset,TRANSFORM(record,SELF := LEFT)).
making it simple to move data from one structure to another without a TRANSFORM as long as all the fields in the output record structure are present in the input recordset.
The transform function must take at least one parameter: a LEFT record of the same format as the recordset. Optionally, it may take a second parameter: an integer COUNTER specifying the number of times the transform has been called for the recordset or the current group in the recordset (see the GROUP function). The second parameter form is useful for adding sequence numbers. The format of the resulting record set does not need to be the same as the input.
Example:
//form one example **********************************
Ages := RECORD
STRING15 per_first_name;
STRING25 per_last_name;
INTEGER8 Age;
END;
TodaysYear := 2001;
Ages CalcAges(person l) := TRANSFORM
SELF.Age := TodaysYear - l.birthdate[1..4];
SELF := l;
END;
AgedRecs := PROJECT(person, CalcAges(LEFT));
//COUNTER example **********************************
SequencedAges := RECORD
Ages;
INTEGER8 Sequence := 0;
END;
SequencedAges AddSequence(Ages l, INTEGER c) :=
TRANSFORM
SELF.Sequence := c;
SELF := l;
END;
SequencedAgedRecs := PROJECT(AgedRecs,
AddSequence(LEFT,COUNTER));
//form two example **********************************
NewRec := RECORD
STRING15 firstname;
STRING25 lastname;
STRING15 middlename;
END;
NewRecs := PROJECT(People,NewRec);
//equivalent to:
//NewRecs := PROJECT(People,TRANSFORM(NewRec,SELF :=
LEFT));
//LOCAL example **********************************
MyRec := RECORD
STRING1 Value1;
STRING1 Value2;
END;
SomeFile := DATASET([{'C','G'},{'C','C'},{'A','X'},
{'B','G'},{'A','B'}],MyRec);
MyOutRec := RECORD
SomeFile.Value1;
SomeFile.Value2;
STRING6 CatValues;
END;
DistFile := DISTRIBUTE(SomeFile,HASH32(Value1,Value2));
MyOutRec CatThem(SomeFile L, INTEGER C) := TRANSFORM
SELF.CatValues := L.Value1 + L.Value2 + '-' +
(Std.System.Thorlib.Node()+1) + '-' + (STRING)C;
SELF := L;
END;
CatRecs := PROJECT(DistFile,CatThem(LEFT,COUNTER),LOCAL);
OUTPUT(CatRecs);
/* CatRecs result set is:
Rec# Value1 Value2 CatValues
1 C C CC-1-1
2 B G BG-2-1
3 A X AX-2-2
4 A B AB-3-1
5 C G CG-3-2
*/
See Also: TRANSFORM Structure, RECORD Structure, ROW, DATASET