Search code examples
hadoopmapreducestatisticshivemode

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.


Solution

  • 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