Search This Blog

Word Count In Hive


In this post I am going to discuss how to write word count program in Hive.

Assume we have data in our table like below

This is a Hadoop Post
and Hadoop is a big data technology

and we want to generate word count like below

a 2
and 1
Big 1
data 1
Hadoop 2
is 2
Post 1
technology 1
This 1

Now we will learn how to write program for the same.


1.Convert sentence into words

 the data  we have is in sentences,first we have to convert that it into words applying space as delimiter.we have to use split function of hive.

split (sentence ,' ')


2.Convert column into rows

Now we have array of strings like this 
[This,is,a,hadoop,Post] 
but we have to convert it into multiple rows like below

This
is
a
hadoop
Post

I mean we have to convert every line of data into multiple rows ,for this we have function called explode in hive and this is also called table generating function.

SELECT explode(split(sentence, ' ')) AS word FROM texttable

and create above output as intermediate table.

(SELECT explode(split(sentence, ' ')) AS word FROM texttable)tempTable

after second step you should get output like below

a
a
and
Big
data
Hadoop
Hadoop
is
is
Post
technology
This


3.Apply group by


after second step , it is straight forward ,we have to apply group by to count word occurrences.

select word,count(1) as count from
(SELECT explode(split(sentence, ' ')) AS word FROM texttable)tempTable
group by word

119 comments:

  1. thank you sir..till now never think of word count using hive

    ReplyDelete
  2. Wow. This is brilliant. Thanks for your help!

    Maria | Owensboro Drywall Contractors

    ReplyDelete
  3. Good article about hadoop technology You may like Updated content at Hadoop Quiz all about hadoop

    ReplyDelete
  4. Thanks for making this blog so informative. www.assistedonlinefilings.com

    ReplyDelete
  5. This article has definitely given me a lot to think about. I am not sure where I stand on the issue yet, but I am grateful for the author's insights.

    Tampa SEO

    ReplyDelete
  6. Thanks for this information you shared. brick masonry

    ReplyDelete
  7. Glad to check this site, thank you for this great content you shared. renovation plastering

    ReplyDelete
  8. Interesting blog! Thanks for taking the time in sharing this post. Grapevine Masonry Grapevine TX

    ReplyDelete
  9. I mean we have to convert every line of data from Castle Drywall in Winston Salem into multiple rows ,for this we have function called explode in hive and this is also called table generating function.

    ReplyDelete
  10. Thank you for the information you shared.
    driveway resurfacing

    ReplyDelete
  11. Thank you for keeping us here posted with new content. commercial epoxy flooring

    ReplyDelete
  12. I'm interested in seeing how you approach the word count calculation in Hive. Will you be using built-in functions or custom UDFs? Also, how do you plan to handle special characters, punctuation, and stop words?

    ReplyDelete
  13. Thanks for the clarification!

    All the best,
    Frisco Concrete Contractors

    ReplyDelete
  14. Thanks for sharing this. It’s exactly what I needed to read today. epoxy shed floor

    ReplyDelete
  15. This is a great blog and very informative. concrete driveway

    ReplyDelete
  16. Glad to check this site. Great post!

    ReplyDelete
  17. Such a great info you shared. Great work! demolition company

    ReplyDelete
  18. Thank you for keeping us posted. Great share! high performance scrubs

    ReplyDelete
  19. I always follow your site for an informative blogs. pool enclosure

    ReplyDelete
  20. Awesome post! Glad to check this site. fence installation

    ReplyDelete
  21. Thank you for taking the time to share this content here. Towing Service New Orleans

    ReplyDelete
  22. Word Count In Hive provide great sources with amazing ideas and roof repair company is offering the best results to us.

    ReplyDelete


  23. Thank you, Sir for sharing more info about Word Hive.

    ReplyDelete
  24. This is amazing! Thanks for taking the time to share this here. concrete contractor

    ReplyDelete
  25. Interesting post! Thank you for the great blog you shared. Zion Roof Pros Roofer

    ReplyDelete
  26. This is awesome! Glad to visit this site. SEO agency

    ReplyDelete
  27. Awesome post, I am def going to follow your blog.

    ReplyDelete
  28. I say to you, I definitely get irked while people think about worries that they just don’t know about.

    ReplyDelete
  29. I appreciate you writing this article plus the rest of the website is also very good.

    ReplyDelete
  30. We met head-on by the concerned industry.

    ReplyDelete
  31. I have been studying your entries all the way through my morning holiday.

    ReplyDelete
  32. Its so fresh, so filled with updates that I just didn’t know.

    ReplyDelete
  33. Hoping to see more of this posts in the future!

    ReplyDelete
  34. This is awesome! I'm glad to check this site. house painters

    ReplyDelete
  35. I really loved it the way of the stuff provided in this article.

    ReplyDelete
  36. You actually make reading enjoyable even for young people.

    ReplyDelete
  37. And all those hours have been fruitfully devoted to learning new things.

    ReplyDelete
  38. Forum where they discuss about this extensively?

    ReplyDelete
  39. I am eternally on a regular basis always.

    ReplyDelete
  40. Some genuinely choice content on this site, saved to favorites.

    ReplyDelete
  41. Very nice input! You are so amazing!

    Cheers from our plaster repair company!

    ReplyDelete
  42. This is one of the good articles you can find in the net explaining everything in detail regarding the will must share this blog and the information i found here really has no value in money but more than it. Thanks for this nice effort which you put here in the shape of this post.

    ReplyDelete
  43. Thanks for taking the time to share this great article here. brick mailbox

    ReplyDelete
  44. Fantastic post but I was wondering if you could write a litte more on this topic?

    ReplyDelete
  45. I will not be reluctant to endorse your web sites to anyone who should receive assistance on this matter.

    ReplyDelete
  46. I can’t help but feel optimistic that this kind of coverage can spark some real momentum. iphone 16 case with card holder

    ReplyDelete
  47. Word Count In Hive is the best for the users in need. Also, you could look here or the right ideas that provide great solutions to us. These people are searching for the best solutions that are good to provide us with results.

    ReplyDelete
  48. I see something truly special in this post.

    ReplyDelete
  49. Glad to visit this informative site. Thanks for sharing. chain link fence

    ReplyDelete
  50. the rest of the website is also very good.

    ReplyDelete
  51. Thanks for this nice effort which you put here in the shape of this post.

    ReplyDelete
  52. I had to go show it to my friend and he enjoyed it as well!

    ReplyDelete
  53. In my nation we need to honer excellent writers.

    ReplyDelete
  54. It seems too Shopping Saver Australia complicated and very broad for me.

    ReplyDelete
  55. So I was hoping to see that kind of value in your posts but Im terribly mistaken.

    ReplyDelete
  56. Now I actually have to wait for a comment confirmation. Heh, now that's what I call growth.

    ReplyDelete
  57. Your structure and pacing make the information easy to absorb.

    ReplyDelete
  58. It’s impressive how much is covered in such a readable way.

    ReplyDelete
  59. This content is packed with genuine insights.

    ReplyDelete
  60. Your insight is genuine and deeply practical.

    ReplyDelete
  61. You probably don’t believe, but if you join you won’t regret.

    ReplyDelete
  62. My partner and I absolutely adore finding internet sites in which appreciate the particular significance.

    ReplyDelete
  63. I know for one, that I will follow your posts in every method I can.

    ReplyDelete
  64. You realize, a lot of persons are hunting around for this info.

    ReplyDelete
  65. Some really nice and useful info on this web site, also I conceive the design and style holds good features.

    ReplyDelete
  66. my office fellow workers to visit your website at the least 3 times every week to learn the fresh tips you have. Bathroom Remodeling Nashville

    ReplyDelete
  67. I be aware like I’m constantly looking in place of engaging things to read almost a heterogeneity of topics.

    ReplyDelete
  68. It's a great site to visit. Keep on sharing here, please. Roofing Company

    ReplyDelete