气流宏未转换为日期

2024-05-20 01:32:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的配置单元操作符,我必须根据日期添加分区

HiveOperator(task_id='add_partition_{}'.format(state),
             hql='alter table my_db.state_wise_records add partition (event_date="{{ ds }}", state="{state}") location "/user/cloudera/state_wise_records/event_date={{ ds }}/state={state}"'.format(state=state),
             dag=dag)

然而,这并不是将宏转换为日期,而不是像下面这样

/user/cloudera/state_wise_records/event_date={ds}/state=UP

这里有什么不对劲


Tags: eventaddformatdateds单元dag分区
1条回答
网友
1楼 · 发布于 2024-05-20 01:32:57

不能将带参数的字符串与Jinja模板结合使用。您将不得不拆分为不同的字符串并连接它们。例如:

hql = 'alter table my_db.state_wise_records add partition (event_date="{{ ds }}",' 
+ 'state="{state}")'.format(state=state) 
+ 'location "/user/cloudera/state_wise_records/event_date={{ ds }}/' 
+ 'state={state}"'.format(state=state)

相关问题 更多 >