Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compute Statistical mode in Hive

How to calculate Statistical Mode in Hive?

Lets say to find the mode for a column in hive table.

Do we have any inbuilt functions for computing Mode.

like image 492
Unmesha Sreeveni U.B Avatar asked Dec 11 '14 10:12

Unmesha Sreeveni U.B


1 Answers

There is no mention of a mode function in the official docs (see Built-in Aggregate Functions).

But the query to get the mode of a column is pretty simple, so a native function might not be necessary.

select age from (
    select age, count(age) as age_cnt
    from mytable
    group by age
    order by age_cnt desc
    limit 1
) t1
like image 192
FuzzyTree Avatar answered Sep 19 '22 14:09

FuzzyTree