I am trying to replace the following using the python Template module.
start_date BETWEEN DATEADD(days,-14,'${DATE_YYYY-MM-DD}') AND '${DATE_YYYY-MM-DD}'
I am using the ConfigParser to read the values and store it into a dictionary(config_params) which i am successfully able to do. Then I am doing a safe substitute to substitute into the above template but it doesnt seem to do anything. It replaces lots of other parameters in the file but just does not seem to replace ${DATE_YYYY-MM-DD}
The code that I am using is below:
with open(templateFile, 'r+') as f:
temp = Template(f.read())
resultFile = temp.safe_substitute(config_params)
Any help on why this is happening ? Is it the () that it does not like ?
TemplateFile:
SELECT
x
,y
,z
,a
,b
INTO ${od}.${tab}
FROM
mphd.${pd} as h
WHERE
a BETWEEN DATEADD(month,-12,'${DATE_YYYY-MM-DD}') AND '${DATE_YYYY-MM- DD}'
;
Config File:
[GeneralParams]
od = sandbox
tab = abcd
pd = hierarchy_expanded
DATE_YYYY-MM-DD = 2016-08-05
config_params:
{'od': 'sandbox', 'DATE_YYYY-MM-DD': '2016-08-05', 'pd': 'hierarchy_expanded', 'tab': 'abcd'}
Result File:
SELECT
x
,y
,z
,a
,b
INTO sandbox.abcd
FROM
mphd.hierarchy_expanded as h
WHERE
a BETWEEN DATEADD(month,-12,'${DATE_YYYY-MM-DD}') AND '${DATE_YYYY-MM- DD}'
;
templateFile, the value ofconfig_params, and the value ofresultFileafter the script is run.