Track 5 Topic 2: Design of Lookups

A lookup is a function that takes a key (string) and returns a scalar value. In this tutorial, we will design two lookups. One is for getting the currency code from account_id. The other is for getting the currency conversion rate (to USD) from a currency code.

1. Design of Lookup currency-code

Assume each account is associated with a different currency code. The account and currency code mapping is as follows:

Account ID, Currency Code
account0000001,USD
account0000002,EUR
account0000003,CNY
account0000004,JPY
account0000005,KRW
account0000006,CAN

Upload this file to cloud storage at

gs://mybucket/testdata/currency_code.txt

Please change the bucket to one of the buckets you own.

Use Calabash GUI, click on “Lookup” at the top of the window to make the Lookup page current. Select “lake_finance” as the data system. Click on the big green button labeled “Create Lookup.”

Fill in the form with the following information.

There are many types of lookups. Select “Text File” for lookup type and put in the location of our lookup file.

Next, we define the structure of each line in the lookup file. This procedure is similar to the text parser we have seen in the previous track. Create the field definitions like the following screenshot.

One of the fields on the text line is the key, and another is the value field. Since the first line in the lookup data file is a title, we can skip it by setting “Number of rows to skip” to 1. The outcome of a lookup can be of any scalar type. For this lookup, select “string.”

Finally, you can optionally put the lookup table on a refresh schedule. By default, the pipeline that uses your lookup loads the lookup file only during the pipeline start-up. But in practice, the lookup table may change over time. For this case, you can define a schedule. Calabash will periodically refresh (i.e., reload and parse the lookup file) the lookup table.

The language for defining the schedule is the cron expression. If you need to learn about the cron expression, please follow the link in the note.

Click “Save” to persist this lookup in the Calabash repository.

2. Design of Lookup currency-conversion-rate

There are many public APIs for currency conversion rates, and Calabash can help you build such lookup. However, to keep the tutorial simple, we will design a “Fixed Data” lookup.

A fixed data lookup contains a static lookup table. You define this lookup table when you design the lookup. See below.

By now, you should be familiar with using the small blue plus-sign to add data to a table. Set the lookup value type to float. Then click on the “Save” button.

A special note: in the above screenshot, you can find the flag for “Encrypt KV table.” If this flag is set, the lookup data will be encrypted before being saved. If you have sensitive data in the lookup table, consider using encryption.