Information icon IBM InfoSphere Information Server, Version 8.1    
space Feedback

Using field lists with operators

You can use field lists when you specify the interface schema to an operator with a dynamic interface.

The following example defines one such operator, called DynamicOperator:

Figure 1. DynamicOperatorDynamicOperator
The operator has the following characteristics: To use this operator, you would specify the field list to its constructor, as shown in the following statement:
static char schema[] =  "record" 					// Schema of input data set
			"( a:int32; "
			" b:int32; "
			" c:int16; "
			" d:sfloat; "
			" e:string; )";
DynamicOperator aDynamicOp("a - c"); 					// Specify the input schema
The following table shows the definition of DynamicOperator. Comments follow the code in the table.
Table 1. DynamicOperator
Comment Code
 
 
 
 
 
 
 
 
 
 
 
8
 
 
 
 
 
 
 
 
 
 
16
17
 
 
 
 
 
 
 
 
23
24
25
26
 
 
 
 
31
32
 
34
35
36
 
 
38
 
 
41
 
42
#include <apt_framework/orchestrate.h>

class DynamicOperator : public APT_Operator
{

	APT_DECLARE_RTTI(DynamicOperator);
	APT_DECLARE_PERSISTENT(DynamicOperator);


	public:
		DynamicOperator();
		DynamicOperator(const APT_FieldList& fList)
				: inSchema(), inFList(fList)
		{}

	protected:
		virtual APT_Status describeOperator();
		virtual APT_Status runLocally();
		virtual APT_Status initializeFromArgs_(const APT_PropertyList
			&args, APT_Operator::InitializeContext context); 

	private:
		APT_Schema inSchema;
		APT_FieldList inFList;

		. . .
	APT_Status DynamicOperator::describeOperator()
	{
		setKind(APT_Operator::eParallel);
		setInputDataSets(1);
		setOutputDataSets(1);

	APT_Schema tempSchema = viewAdaptedSchema(0);
	APT_FieldList::Error err;
	inFList.expand(tempSchema, &err);
	if (err.errorOccurred()) 
	{ 
		reportError(err.description()); 
		return APT_StatusFailed; 
	}
	int numFields = inFList.numFields();
	for (int n = 0; n < numFields; n++) 
	{
		APT_FieldSelector fs = inFList.field(n);
		APT_SchemaField f = tempSchema.field(fs);
		inSchema.addField(f);
	}

	APT_SchemaField inField;
	inField.setIdentifier("inRec");
	inField.setTypeSpec("*");
	inSchema.addField(inField);

	setInputInterfaceSchema(inSchema, 0);
	setOutputInterfaceSchema("record (outRec:*;)", 0);

	declareTransfer("inRec", "outRec", 0, 0);

	Return APT_StatusOk;
}
8
Define a constructor that takes a field list as an argument.
16
Define storage for the complete input interface schema to the operator.
17
Define storage for the input field list specifying the input schema.
23
Use APT_Operator::viewAdaptedSchema() to obtain the complete record schema of the input data set. You will expand the input field list in the context of the input data set record schema.
24
Define err, an instance of APT_FieldList::Error, to hold any errors generated when expanding the field list.
25
Use APT_FieldList::expand() to expand the field list relative to the record schema of the input data set. If the field list does not contain a wildcard or field range, the expand function does nothing.
26
If any errors occurred during the expansion, print the description of the error and return APT_StatusFailed from describeOperator().
31
Use APT_FieldList::numFields() to determine the number of fields in the field list.
32
Create a for loop to iterate through the field lists. For each element in the field list, add a schema field to inSchema, the input interface schema of the operator.
34
Use APT_FieldList::field() to get a field selector from the expanded field list.
35
Use APT_Schema::field() to return an APT_SchemaField object corresponding to a record schema field of the input data set.
36
Use APT_Schema::addField() to add the APT_SchemaField object to inSchema.
38 - 41
After adding all the fields of the field list to the input interface schema, you must create a schema field component for the schema variable "inRec:*;" and add that component to the input interface schema. Use APT_Schema::addField() to add the schema variable to allow transfers from the input data set to the output data set.
42
Use APT_Operator::setInputInterfaceSchema() to set the input interface schema of the operator to the schema contained in inSchema.



Update timestamp Last updated: 2010-03-30