Dai9210
4 years agoNew Contributor II
Create a reusable pipeline to dynamic apply default value
Here is the scenario:
I want to apply default value to a table, and the column(s) which need to apply default value might be changed. What I am doing is to:
- Create a parameter csv file with the same column names as the source table.
- Join the source table with the csv file on 1=1, then the csv columns will get a prefix ‘input1_’.
- By using hasOwnProperty , it will be able to apply the default value from the csv file to the source table. e.g.
$.hasOwnProperty('input1_COUNTRYCODE')?$input1_COUNTRYCODE: $COUNTRYCODE
to apply the default value for [COUNTRYCODE] column.
My question is, if there is 100 columns in the source table, I need to create 100 hasOwnProperty in the mapper and if the column names in the source table changed I have to modify those expressions, so, is it any expression could get the field names dynamic to replace this COUNTRYCODE in the expression?
Source table:
[
{
"BANKNAME": "Test Bank 001",
"BANKNUMBER": "Test123",
"COUNTRYCODE": "US01"
},
{
"BANKNAME": "Test Bank 002",
"BANKNUMBER": "Test456",
"COUNTRYCODE": "US02"
}
]
Parameter file (default value):
"COUNTRYCODE":"US"