Joke D
Joke D

Reputation: 1

Counting in Hadoop Hive And Show the result more than a given num

I want to count values similar in a map where key would be the value in the Hive table column and the corresponding value is the count. And count is more than a given num x.

For example, query:

SELECT Col1, COUNT(*) FROM Table GROUP BY Col1

result:

Key1=2
Key2=1

and the given num x=2. So the hive query should return something like :

Key1=2.

explain:

Key1=2 >=2 (ok)
Key2=1 <2  (not ok)

Upvotes: 0

Views: 652

Answers (1)

leftjoin
leftjoin

Reputation: 38335

Map will be displayed like {"Key1":2} If you want Key1=2 then use concat(Col1, '=', cnt) instead of map():

select map(Col1, cnt) as mymap
from(
SELECT Col1, COUNT(*) cnt 
  FROM Table 
 GROUP BY Col1 
HAVING count(*)>=2 --Magic number filter here
)s;

Upvotes: 1

Related Questions