..Continue from Part 2..
Runtime behavior of REFORMAT
- First it read the port count(n) from count parameter of component the n in outn gives each out port a unique number. Each outn port has a corresponding rejectn and errorn port. REFORMAT does the following:
- REFORMAT reads a record from the in port of component.
- If the select parameter has an expression specified, It uses the expression to evaluate the input record:
- if the expression evaluates to false (0), then REFORMAT discards the input record and starts over with step 1.
- If the expression produces NULL, then REFORMAT writes a descriptive error message and stops execution of the graph.
- If the expression evaluates to true (anything other than 0 or NULL), then REFORMAT begins processing the input record.
3. If the select parameter does not have a value, REFORMAT begins processing the input record.
4. REFORMAT determines whether a transform function is specified in either the output-index or output-indexes parameter:
- If neither output-index nor output-indexes has a value (the usual case when there is only one out port), REFORMAT sends the input record to every transform-out port pair, beginning with out0 and progressing sequentially.
- If output-index or output-indexes has a value, REFORMAT evaluates the specified index transform. If output-indexes is defined, it should return a vector of port index values. If output-index is defined, it should return a single port index value.
- REFORMAT uses one or more values from the index transform to determine the appropriate transform-output port pair or pairs for the input record. If the index transform returns more than one value, REFORMAT sends the record to each of the appropriate ports, starting with the lowest numbered port and progressing to the other ports sequentially.
5. REFORMAT determines whether each outn port has a transform function.
- If an out port does not have a transform function, REFORMAT uses implicit reformat to process the input record. For more information, see “Implicit reformat”.
- If the input record is sent to more than one port, the order of the transform evaluation is sequential: it calls the transform function on each port in order, starting with the lowest numbered port. For example, if the record is to be sent to port0 and port2, it is sent to port0 first, and then to port2. The evaluation of the second transform can depend on the side-effects of the first transform, which means you could make successive calls to a function like next_in_sequence from sequential transforms for the same input record
- If a transform function results in an error or returns NULL, REFORMAT writes the following:
- An error message to the corresponding error port
- The current input record to the corresponding reject port
- The component stops execution of the graph when the number of reject events exceeds the reject threshold.
- if the reject or error ports do not have flows attached to them, REFORMAT discards the record.
6. REFORMAT writes the record to the out port of each successful transform,and then begins processing the next input record.