Docs file (Input File)
Mary had a little lamb
its fleece was white as snow
and everywhere that Mary went
the lamb was sure to go.
Hive Query
CREATE TABLE FILES (line STRING);
LOAD DATA INPATH 'docs' OVERWRITE INTO TABLE FILES;
CREATE TABLE word_counts AS
SELECT word, count(1) AS count FROM
(SELECT explode(split(line, ' ')) AS word FROM FILES) w
GROUP BY word
ORDER BY word;
Output of word_counts table in Hive
Mary,2
had,1
a,1
little,1
lamb,2
its,1
fleece,1
was,2
white,1
as,1
snow,1
and,1
everywhere,1
that,1
went,1
the,1
sure,1
to,1
go,1