Example: Derivation of a composite operator
This example gives the code for a composite operator.
The following code shows the class definition for a composite operator
derived from APT_CompositeOperator:
| Line number (Comment) | Code |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- 2
- Derive this class from APT_CompositeOperator.
- 9
- Override describeOperator(). You cannot override APT_Operator::runLocally for a composite operator.
- 11
- Define a pointer to a temporary data set that connects the two suboperators. This data set will be dynamically allocated in the constructor for RemoveDuplicates.
- 12
- Dynamically allocate the suboperators of the composite operator. This line defines sortOp, a pointer to a SortOperator, as a private data member of the composite operator. You instantiate SortOperator in the constructor for RemoveDuplicates.
- 13
- Define removeOp, a pointer to a RemoveOperator, as a private data member of the composite operator.
- 14
- See the header file, argvcheck.h, for documentation on the ARGS_DESC string.
- 15
- With APT_DEFINE_OSH_NAME, you connect the class name to the name used to invoke the operator from osh and pass your argument description string. See osh_name.h for documentation on this macro.
- 16- 17
- APT_IMPLEMENT_RTTI_ONEBASE and APT_IMPLEMENT_PERSISTENT are required macros that implement run-time information and persistent object processing.
- 18
- With your override of initializeFromArgs_(), you transfer information from the arguments to the class instance. Because there are no arguments for this example, initializeFromArgs_() returns APT_StatusOk. See the header file, operator.h for documentation on this function.
- 22
- The constructor for RemoveDuplicatesOperator must instantiate the suboperators and tie together the suboperators and temporary data sets that make up the composite operator. In this example, you must specify tempDS as the output data set of sortOp and the input data set of removeOp.
- 24
- Dynamically allocate a data set.
- 25 -26
- Dynamically allocate a SortOperator object
and a RemoveOperator object. Both are derived from
APT_Operator.
Subops must be allocated dynamically. They are deleted by InfoSphere DataStage using the default destructor, and must not be deleted or serialized by the composite operator.
- 27
- Specify tempDS as the output data set of sortOp. You need not specify an input data set. The function APT_CompositeOperator::redirectInput() in the override of APT_Operator::describeOperator() specifies the input data set. See the override of APT_Operator::describeOperator().
- 28
- Specify tempDS as the input data set of removeOp. You do not have to specify an output data set. The function APT_CompositeOperator::redirectOutput() in the override of APT_Operator::describeOperator() specifies the output data set.
- 36
- Specify sortOp as a suboperator.
- 37
- Specify removeOp as a suboperator.
- 38
- Use APT_CompositeOperator::redirectInput() to specify that the data set input to sortOp corresponds to the first data set input to the composite operator.
- 39
- Use APT_CompositeOperator::redirectOutput() to specify that the data set output by removeOp corresponds to the first data set output by the composite operator.