我的表每天运行,每天生成一个名为date的分区cloumn例如:我的查询生成日期
2018-01-012018-01-022018-01-032018-01-062018-01-08``` `2018-01-05 & 2018-01-07` 日期不见了。有没有办法找出那些丢失的日期?
2018-01-01
2018-01-02
2018-01-03
2018-01-06
2018-01-08
``` `2018-01-05 & 2018-01-07` 日期不见了。有没有办法找出那些丢失的日期?
l0oc07j21#
下面的查询将1)创建一个临时表,其中包含从开始分区日期到最新分区日期的连续日期2)执行左连接,查看缺少哪些分区日期(partition\u dt为null)。希望这有帮助。谢谢。
create table partition_dtes as with cal_date as (select min(partition_dt) as min_dt, max(partition_dt) as max_dt from mytable) select date_add(t.min_dt, pe.idx) as series_dtefrom cal_date tlateral viewposexplode(split(space(datediff(t.max_dt,t.min_dt)),' ')) pe as idx, dte; Result: 2018-01-012018-01-022018-01-032018-01-042018-01-052018-01-062018-01-072018-01-08select distinct dte.series_dtefrom partition_dtes dteleft join mytable tblon dte.series_dte=tbl.partition_dtwhere tbl.partition_dt is nullorder by dte.series_dte;Result: 2018-01-04 2018-01-05 2018-01-07
create table partition_dtes as
with cal_date as (select min(partition_dt) as min_dt, max(partition_dt) as max_dt from mytable)
select date_add(t.min_dt, pe.idx) as series_dte
from cal_date t
lateral view
posexplode(split(space(datediff(t.max_dt,t.min_dt)),' ')) pe as idx, dte;
Result:
2018-01-04
2018-01-05
2018-01-07
select distinct dte.series_dte
from partition_dtes dte
left join mytable tbl
on dte.series_dte=tbl.partition_dt
where tbl.partition_dt is null
order by dte.series_dte;
1条答案
按热度按时间l0oc07j21#
下面的查询将1)创建一个临时表,其中包含从开始分区日期到最新分区日期的连续日期2)执行左连接,查看缺少哪些分区日期(partition\u dt为null)。希望这有帮助。谢谢。