If you just want to look at those groups, you can simply write:
select id, val
from tableX
order by val;
If you need to have those groups separated as different object, then you can use something like:
select val, collect_set(id)
from tableX
group by val;
Or (if the val is not important)
select collect_set(id)
from tableX
group by val;
Those queries will produce arrays of id's with no duplicates. collect_list
(as of hive 0.13) is for aggregating collections with duplicates.