在aws数据管道中传递给sql活动的处理参数

bwleehnv  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(310)

我正在使用aws数据管道。在此上下文中,我将几个参数从管道定义传递到sql文件,如下所示:

s3://reporting/preprocess.sql,-d,RUN_DATE=#{@scheduledStartTime.format('YYYYMMdd')}"

我的sql文件如下所示:

CREATE EXTERNAL TABLE RESULT (
STUDENT_ID            STRING,
REMARKS               STRING,
EXAM_DATE             STRING
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE LOCATION  's3://result/data/run_date=${previous day of RUN_DATE}';  <----(1)

...
insert into temp
select a.roll_number, remarks
from student a inner join result b
on a.student_id = b.student_id
where exam_date>='<start date of previous month of RUN_DATE>' <---- (2)
and exam_date<='<end date of previous month of RUN_DATE>';<---- (3)

在上面的sql中,我不知道如何从run\u date实现(1)、(2)和(3)。
因此,如果run_date=20190101,则(1)中的值应为“20181231”,(2)中的值应为“2018-12-01”,(3)中的值应为“2018-12-31”。

enyaitl3

enyaitl31#

您可以在sql中使用配置单元日期函数来获得所需的结果:
前一天: date_sub(RUN_DATE,1) 上月开始日期: date_add(last_day(add_months(RUN_DATE, -2)),1) 上月结束日期: last_day(add_months(RUN_DATE, -1))

相关问题