我正在使用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_DATE实现(1),(2)和(3)。
因此,如果RUN_DATE = 20190101,则(1)中的值应为“ 20181231”,(2)中的值应为“ 2018-12-01”,而(3)应为“ 2018-12-31”。 / p>
答案 0 :(得分:0)
您可以在SQL中使用HIVE Date函数来获得所需的结果:
date_sub(RUN_DATE,1)
date_add(last_day(add_months(RUN_DATE, -2)),1)
last_day(add_months(RUN_DATE, -1))