...
Lookup interface
Code Block 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)
Code Block "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 LookupKV Lookup instance to script
Options for lookup usage:
Code Block var result = context.getTablegetLookup("purchases").lookup(user); // or var result = tables["purchases"].lookup(user); // or var result = purchases.lookup(user);
Options for batch lookup usage:
Code Block var result = context.getLookup("purchases").lookup(["alice", "bob"]); // do something with result["alice"] // do something with result["bob"]
...