...
- Operations
- Perform single + batch read on single + multiple dataset from script transform
- Perform single + batch read on DistributedCache single + multiple files from script transform
- Supported datasets tables for lookup
- Key
- KeyValueTable dataset
- ObjectMappedTable dataset
- CSV files treated as a list of key-value tablepairs
- ObjectMappedTable
- Optional caching with time-based expiration
Proposed changes
- TransformContext changes
- Rename TransformContext to StageContext (since it is used as the base context in BatchRuntimeContext, not only transform contexts).
- Create TransformContext which extends StageContext
- Transform changes
- Lookup interface with lookup methods that perform read operations on datasets
- DefaultLookup: implementation that uses Transactional to implement Lookup, used in ETLWorker Add Lookup field to ScriptContext, so Lookup is accessible via transforms that interpret JavaScriptSample usage: ctx.lookup.lookupKVString('purchases', 'key')
Design
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 Lookup instance to script
Options for lookup usage:
Code Block var result = context.getLookup("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"]