Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize WordCount with Hive

Shulou Source: shulou.com Published: 2022-06-01 01:46:39 09月28日 Update

This article will explain in detail how to achieve WordCount in Hive. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

1. Create a table (external table) t_words_src that stores the source data. The field line in the table is of type string and holds one line of words.

Source data shows the column:

Hello,tomhello,jerryhello,kittyhello,worldhello,tomhive > create external table t_words_src (line string) row format delimitedfields terminated by'\ n'# Press\ n to split the field. One line is a field. The source data path of location'/ wc/input'; # is' hdfs://node1:9000/wc/input' hive > select * from tweewords.There is OKhello.tomhello.jerryhello.jittyhello.worldhellotom.hello.jerryhello.jittyhello.worldhellotom.jerryhello.jittyhello.World hello.tom

two。 Create a table t _ words that stores all words. The field word in the table is of type string, and the words are stored.

Hive > create table t_words (word string); hive > insert into table t_words select explode (split (line,',')) as word from tasking wordsThe world hellotom

3. Create a table t _ wc_result to store WordCount results. The field word in the table is of string type, the counts is of int type, and the number of occurrence of words is stored.

Hive > create table t_wc_result (word string, counts int); hive > insert into table t_wc_result select word as word, count (word) as counts from tasking wordsThere is Hive > select * from tincture wcking result: OKhello 5jerry 1kitty 1tom 2world 1

Compared with MapReduce, Hive's HQL version of WordCount has much less code to write, but their ideas are all the same.

On how to achieve Hive WordCount to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Words fields types data one line content articles more knowledge articles yes code that is thoughts times results quality paths references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS vpn Apple Shulou Information