我正在尝试进行简单的hive转换。
有人可以为我提供一种方法吗?我已经尝试过collect_set,目前正在查看klout的开源UDF。
答案 0 :(得分:1)
我认为这会给你你想要的东西。我无法运行它并调试它。祝你好运!
select start_point.unit
, start_time as start
, start_time + min(stop_time - start_time) as stop
from
(select * from
(select date_time as start_time
, unit
, last_value(unit) over (order by date_time row desc between current row and 1 following) as previous_unit
from table
) previous
where unit <> previous_unit
) start_points
left outer join
(select * from
(select date_time as stop_time
, unit
, last_value(unit) over (order by date_time row between current row and 1 following) as next_unit
from table
) next
where unit <> next_unit
) stop_points
on start_points.unit = stop_points.unit
where stop_time > start_time
group by start_point.unit, start_time
;
答案 1 :(得分:0)
使用min和max函数怎么样?我认为以下内容可以满足您的需求:
SELECT
Unit,
MIN(datetime) as start,
MAX(datetime) as stop
from table_name
group by Unit
;
答案 2 :(得分:0)
我找到了。感谢指针使用窗口函数
arp.ar_hrd=htons(ARPHRD_ETHER);
arp.ar_pro=htons(ETHERTYPE_IP);
arp.ar_hln=6;
arp.ar_pln=4;
arp.ar_op=htons(ARPOP_REQUEST);
arp.ar_sha=ether_aton("ss:ss:ss:ss:ss:ss");
arp.ar_spa=inet_addr("192:168:32:128");
arp.ar_tha=ether_aton("ff:ff:ff:ff:ff:ff");
arp.arp_tpa=inet_addr("192.168.32.1");
答案 3 :(得分:0)
create table temptable as select unit, start_date, end_time, row_number () over() as row_num from (select unit, min(date_time) start_date, max(date_time) as end_time from table group by unit) a;
select a.unit, a.start_date as start_date, nvl(b.start_date, a.end_time) end_time from temptable a left outer join temptable b on (a.row_num+1) = b.row_num;