Lookup in Transforms
Requirements
- Operations
- Perform single + batch read on single + multiple dataset from script transform
- Perform single + batch read on single + multiple files from script transform
- Supported tables for lookup
- KeyValueTable dataset
- ObjectMappedTable dataset
- CSV files treated as a list of key-value pairs
- Optional caching with time-based expiration
Design
 Lookup interfaceÂ
interface Lookup<T> { T lookup(String key); Map<String, T> lookup(String... keys); Map<String, T> lookup(Set<String> keys); }
- Implement Lookup in KeyValueTable and ObjectMappedTable
- KeyValueTable implements Lookup<String>
- ObjectMappedTable implements Lookup<StructuredRecord>
- DatasetConfigurer changes
- Add method: void useDataset(String datasetName);
- ScriptTransform changes
Add configuration property for declaring lookup tables to use, properties for each table (e.g. dataset properties)
"tables": [ { "name":"purchases", "type":"dataset", "properties": { "dataset":"purchases", "properties":{.. dataset properties ..}, "enableCache":"true", "cacheExpiry":1234 } }, {"name":"ip2geo", "type":"file", "properties":{"file":"/data/ip2geo.csv"}} ]
- configure(): verify tables (datasets and files) exist by calling DatasetConfigurer.useDataset()
- transform(): execute lookup methods in a transaction, provide Lookup instance to script
Options for lookup usage:Â
var result = context.getLookup("purchases").lookup(user);
Options for batch lookup usage:
var result = context.getLookup("purchases").lookup(["alice", "bob"]); // do something with result["alice"] // do something with result["bob"]
Â