My goal is to return 1st day of previous month based on airflow macro variable {{ds}} and use it e.g. in HiveOperator.
E.g. For ds = 2020-05-09 I expect to return: 2020-04-01
The solution I found and tried were:
SET hivevar:LAST_MONTH='{{ (ds.replace(day=1) - macros.timedelta(days=1)).replace(day=1) }}';
SET hivevar:LAST_MONTH='{{ ds + macros.dateutil.relativedelta.relativedelta(months=-1, day=1) }}'
But both resulted in errors:
Error rendering template: replace() takes no keyword arguments
Error rendering template: must be str, not relativedelta
and when rendered didn't show any dates.
What am I doing wrong?
