PROCESS

PROCESS(recordset, datarow, datasettransform, rowtransform [, LOCAL ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

recordsetThe set of records to process.
datarowThe initial RIGHT record to process, typically expressed by the ROW function.
datasettransformThe TRANSFORM function to call for each record in the recordset.
rowtransformThe TRANSFORM function to call to produce the next RIGHT record for the datasettransform.
LOCALOptional. Specifies the operation is performed on each supercomputer node independently, without requiring interaction with all other nodes to acquire data; the operation maintains the distribution of any previous DISTRIBUTE.
UNORDEREDOptional. Specifies the output record order is not significant.
ORDEREDSpecifies the significance of the output record order.
boolWhen False, specifies the output record order is not significant. When True, specifies the default output record order.
STABLEOptional. Specifies the input record order is significant.
UNSTABLEOptional. Specifies the input record order is not significant.
PARALLELOptional. Try to evaluate this activity in parallel.
numthreadsOptional. Try to evaluate this activity using numthreads threads.
ALGORITHMOptional. Override the algorithm used for this activity.
nameThe algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options.
Return:PROCESS returns a record set.

The PROCESS function operates in a similar manner to ITERATE in that it processes through all records in the recordset one pair of records at a time, performing the datasettransform function on each pair of records in turn. The first record in the recordset is passed to the datasettransform as the first left record, paired with the datarow as the right record. The rowtransform is used to construct the right record for the next pair. If either the datasettransform or the rowtransform contains a SKIP, then no record is produced by the datasettransform for the skipped record.

TRANSFORM Function Requirements - PROCESS

The datasettransform and rowtransform functions both must take at least two parameters: a LEFT record of the same format as the recordset and a RIGHT record of the same format as the datarow. The format of the resulting record set for the datasettransform both must be the same as the input recordset. The format of the resulting record set for the rowtransform both must be the same as the initial datarow. Optionally, the datsettransform may take a third 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).

Example:

DSrec := RECORD
  STRING4 Letter;
  STRING4 LeftRecIn := '';
  STRING4 RightRecIn := '';
END;
StateRec := RECORD
  STRING2 Letter;
END;
ds := DATASET([{'AA'},{'BB'},{'CC'},{'DD'},{'EE'}],DSrec);

DSrec DSxform(DSrec L,StateRec R) := TRANSFORM
  SELF.Letter := L.Letter[1..2] + R.Letter;
  SELF.LeftRecIn := L.Letter;
  SELF.RightRecIn := R.Letter;
END;
StateRec ROWxform(DSrec L,StateRec R) := TRANSFORM
  SELF.Letter := L.Letter[1] + R.Letter[1];
END;

p := PROCESS(ds,
             ROW({'ZZ'},StateRec),
             DSxform(LEFT,RIGHT),
             ROWxform(LEFT,RIGHT));
OUTPUT(p);
/* Result:
AAZZ AA ZZ
BBAZ BB AZ
CCBA CC BA
DDCB DD CB
EEDC EE DC */

//******************************************************************
// This examples uses different information for state tracking
// (the point of the PROCESS function) through the input record set.
  
w1 := RECORD
  STRING v{MAXLENGTH(100)};
END;

s1 := RECORD
  BOOLEAN priorA;
END;

ds := DATASET([{'B'},{'A'}, {'C'}, {'D'}], w1);

s1 doState(w1 l, s1 r) := TRANSFORM
  SELF.priorA := l.v = 'A';
END;

w1 doRecords(w1 l, s1 r) := TRANSFORM
  SELF.v := l.v + IF(r.priorA, '***', '');
END;

initState := ROW({TRUE}, s1);

rs := PROCESS(ds,
              initState,
              doRecords(LEFT,RIGHT),
              doState(LEFT,RIGHT));

OUTPUT(rs);
/* Result:
B***
A
C***
D
*/

See Also: TRANSFORM Structure, RECORD Structure, ROW, ITERATE