hive-日期拆分为多行
代码
sql
SELECT begin_date,
date_add(begin_date, tmp.pos),
end_date,
d_days,
tmp.pos,
tmp.val
FROM (
SELECT begin_date,
end_date,
DATEDIFF(end_date, begin_date) AS d_days
FROM (
SELECT '2025-08-01' AS begin_date,
'2025-08-10' AS end_date
) a
) b LATERAL VIEW posexplode(split(space(d_days), '')) tmp AS pos,
val
结果
sql
begin_date _col1 end_date d_days pos
2025-08-01 2025-08-01 2025-08-10 9 0
2025-08-01 2025-08-02 2025-08-10 9 1
2025-08-01 2025-08-03 2025-08-10 9 2
2025-08-01 2025-08-04 2025-08-10 9 3
2025-08-01 2025-08-05 2025-08-10 9 4
2025-08-01 2025-08-06 2025-08-10 9 5
2025-08-01 2025-08-07 2025-08-10 9 6
2025-08-01 2025-08-08 2025-08-10 9 7
2025-08-01 2025-08-09 2025-08-10 9 8
2025-08-01 2025-08-10 2025-08-10 9 9