示例1:
现要生成start_time('2020-11-01')到end_time("2020-11-30")之间的所有日期
select i, date_add('2020-11-01', pe.i) as dynamic_date ,'2020-11-01' as start_time, '2020-11-30' end_time from ods.test lateral view posexplode(split(space(datediff('2020-11-30', '2020-11-01')),' ')) pe as i, x limit 30 ;
ps:第一列为生成的索引值。其中的space函数为要生成几个空格,方便以空格切分生成对应的索引个数。
结果:
参考:
示例2:
SELECT single_id, single_time FROM tempTable lateral view posexplode(split(id,',')) as single_id_index,single_id lateral view posexplode(split(time,',')) as single_time_index,single_time WHERE single_id_index=single_time_index
spark两种实现方式:
需求:
实现:
参考: