User guide

Data Integration with Sybase Avaki Studio 115
Custom
algorithm with the second input result set as the inner table. This would produce a
result set consisting of:
ACCT_NO - the account number for the transaction
SYMBOL - the symbol of the stock purchased
NO_OF_SHARES - the number of shares of stock purchased
COST - the cost per share
CURRENCY - the currency in which COST is expressed (from the first input)
CURRENCY - the currency for which the conversion factor applies (from the
second input)
MULTIPLIER - the factor by which the original value is multiplied to get the
Euro value
You could then use a Projection operator to remove the unneeded columns and to
compute the COST_IN_EURO column (the formula being NO_OF_SHARES * COST *
MULTIPLIER
).
Solving the problem with a Custom operator
An alternative implementation for this same functionality is to use a Custom operator
to build a lookup table that maps currency to multiplier and then performs the compu-
tation as you read in the account result set.
Note This technique is presented here to illustrate, using a relatively simple
problem, how to use Custom operators—not necessarily as a recommendation
for best practices.
This example uses a .jsi file as well as a Custom operator. The .jsi file contains the fol-
lowing JavaScript:
var lookupTable = {}; // This will contain the mapping of currency type to
conversion factor.
function setUpLookupTable(rs) {
if (lookupTable.initialized == true) {
return; // We only need to read the result set into the map once
}
while (rs.next()) { // Iterate over the rows in the result set
var key = rs.getString(rs, "CURRENCY"); // Get the currency type
var value = rs.getRealValue("MULTIPLIER"); // Get the conversion factor
lookupTable[key] = value; // Save the key/value pair
}