This is not the most efficient way, but it works.
SELECT name, min(time) AS start,max(time) As end FROM ( SELECT name,time, time- DENSE_RANK() OVER (partition by name ORDER BY time) AS diff FROM foo ) t GROUP BY name,diff;
I would suggest trying the following query and building GenericUDF to define spaces, much easier :)
SELECT name, sort_array(collect_list(time)) FROM foo GROUP BY name;
source share