Changing the key names dynamically
- 2 years ago
sravan - I'm sure others have their own ways to do things like this, but I'm partial to expression libraries, especially when you have multiple definitions to work with. Download the attached zip file and import the pipeline and file to your project.
In the file, you will notice that it is named based on the table name, in this case "test_table", and the contents have an "xref" object defined with the source key names, and the desired key names.
In the pipeline, the Mapper is using the Object.mapKeys() method to translate the key names by doing an Object.get() call to ensure that the source key name has been defined in the expression file and will default to the source key name from the input view if it doesn't exist.
Also in the pipeline is a dynamic reference to the library expression file based on the table_name pipeline parameter value, and aliased as "tbldef" so it can be referenced in an expression consistently regardless of the actual table name being processed. This will allow you to have one definition file per table, making it easier to maintain. Assuming you are using a parent pipeline to call a child and passing the name of the table to be processed as a pipeline parameter, this should be easy for you to incorporate.
Hope this helps!