User guide
Operator reference
116 Data Integration with Sybase Avaki Studio
lookupTable.initialized = true; // So we don't try and do this again
}
This code reads the “currency to exchange rate” result set into a hash table. The Cus-
tom operator has two inputs—one is called “LookupTableSource,” and the other is
called “DataInputSource.”
The logic in the Custom operator itself is as follows (remember that this is a function
with a Boolean return value—Studio supplies the outer braces, you only type the func-
tion body):
// Note that this function requires the lookup table input source to be named
// "LookupTableSource" and the main input source to be named "DataInputSource"
setUpLookupTable(LookupTableSourceRS); // Initialize the lookup table
// Check to see if there are more rows in DataInputSourceRS. If not, return false
// Note that this also advances the row pointer to the DataInputSourceRS
if (DataInputSourceRS.next() == false) {
return false;
}
// Get the values of the fields we need from the input result set
var accountNumber = DataInputSourceRS.getInt("ACCOUNT_NO");
var symbol = DataInputSourceRS.getString("SYMBOL");
var currencyType = DataInputSourceRS.getString("CURRENCY");
var numShares = DataInputSourceRS.getInt( "NO_OF_SHARES");
var costPerShare = DataInputSourceRS.getFloat("COST");
// Look up the Euro conversion factor for the original currency
var conversionFactor = lookupTable[currencyType];
// Compute the value of the transaction, in Euros
var totalValue = numShares * costPerShare * conversionFactor;
// Store the values in the output result set
outputRS.updateInt("ACCOUNT_NO", accountNumber);
outputRS.updateString("SYMBOL", symbol);
outputRS.updateString("COST_IN_EURO", totalValue);
return true; // Let the runtime know we provided another row