识别配置单元表中缺少的分区

xj3cbfub  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(427)

我的表每天运行,每天生成一个名为date的分区cloumn
例如:我的查询生成日期

  1. 2018-01-01
  2. 2018-01-02
  3. 2018-01-03
  4. 2018-01-06
  5. 2018-01-08
  6. ``` `2018-01-05 & 2018-01-07` 日期不见了。有没有办法找出那些丢失的日期?
l0oc07j2

l0oc07j21#

下面的查询将1)创建一个临时表,其中包含从开始分区日期到最新分区日期的连续日期2)执行左连接,查看缺少哪些分区日期(partition\u dt为null)。希望这有帮助。谢谢。

  1. create table partition_dtes as
  2. with cal_date as (select min(partition_dt) as min_dt, max(partition_dt) as max_dt from mytable)
  3. select date_add(t.min_dt, pe.idx) as series_dte
  4. from cal_date t
  5. lateral view
  6. posexplode(split(space(datediff(t.max_dt,t.min_dt)),' ')) pe as idx, dte;
  7. Result:
  8. 2018-01-01
  9. 2018-01-02
  10. 2018-01-03
  11. 2018-01-04
  12. 2018-01-05
  13. 2018-01-06
  14. 2018-01-07
  15. 2018-01-08
  16. select distinct dte.series_dte
  17. from partition_dtes dte
  18. left join mytable tbl
  19. on dte.series_dte=tbl.partition_dt
  20. where tbl.partition_dt is null
  21. order by dte.series_dte;
  22. Result:
  23. 2018-01-04
  24. 2018-01-05
  25. 2018-01-07
展开查看全部

相关问题