Pick a random row as an aggregate function in Hive

I want to group by column and then select random rows from another column. The Presto exists arbitrary

.

eg. my request:

SELECT a, arbitrary(b)
FROM foo
GROUP BY a

      

How do I do this in Hive?

Edit:

By "random" I mean "arbitrary". This can only be the first row each time.

+3


source to share


1 answer


select      a,min(b)
from        foo
group by    a

      

or

select      a,max(b)
from        foo
group by    a

      



or

select      a,max(named_struct('r',rand(),'b',b)).b
from        foo
group by    a

      

0


source







All Articles