Saturday 17 May 2014

Count Frequency Of Values In A Column Using Apache Pig


There may be situations to count the occurence of a value in a field.
Let this be the sample input bag.


user_id   course_name user_name
1           Social      Anju
2           Maths       Malu
1           English     Anju
1           Maths       Anju

Say we need to calculate no of occurence of each user_name.
Anju 3
Malu 1

Inorder to achieve this - COUNT Built In Function can be used.


COUNT Function in Apache Pig


COUNT function  compute the number of elements in a bag.
To group count a preceding GROUP BY statement and for global counts GROUP ALL statement is required.

The basic idea to do the above example is to group by user_name and count the tuples in the bag.


--count.pig

 userAlias = LOAD '/home/sreeveni/myfiles/pig/count.txt' as 
             (user_id:long,course_name:chararray,user_name:chararray);
 groupedByUser = group userAlias by user_name;
 counted = FOREACH groupedByUser GENERATE group as user_name,COUNT(userAlias) as cnt;
 result = FOREACH counted GENERATE user_name, cnt;
 store result into '/home/sreeveni/myfiles/pig/OUT/count';

The COUNT function ignores NULLs, that is tuple in the bag will not be counted if the first field in this tuple is NULL.
COUNT_STAR can be used to count fields including NULL values.




23 comments:


  1. Worthful Hadoop tutorial. Appreciate a lot for taking up the pain to write such a quality content on Hadoop tutorial. Just now I watched this similar Hadoop tutorial and I think this will enhance the knowledge of other visitors for sure. Thanks anyway.:https://www.youtube.com/watch?v=1jMR4cHBwZE

    ReplyDelete
  2. Top Trending Technologies of 2019. Watch here:https://www.youtube.com/watch?v=-y5Z2fmnp-o

    ReplyDelete
  3. Very Impressive Big Data Hadoop tutorial. The content seems to be pretty exhaustive and excellent and will definitely help in learning Big Data Hadoop course. I'm also a learner taken up Big Data Hadoop Tutorial and I think your content has cleared some concepts of mine. While browsing for Hadoop tutorials on YouTube i found this fantastic video on Big Data Hadoop Tutorial.Do check it out if you are interested to know more.https://www.youtube.com/watch?v=nuPp-TiEeeQ&

    ReplyDelete
  4. Trade Stocks, Forex, And Bitcoin Anywhere In The World:tradeatf Is The Leading Provider Of Software That Allows You To Trade On Your Own Terms. Whether You Are Operating In The Forex, Stock, Or Cryptocurrency Markets, Use tradeatf Software And Anonymous Digital Wallet To Connect With The Financial World.: tradeatf Is A Currency Trading Company That Allows You To Trade Stocks, Forex, And Cryptocurrency.

    ReplyDelete
  5. AximTrade Review Is A Forex And Cfd Broker. It Offers Trading In Currency Pairs, Commodities, Indices, And Shares. It Also Provides A Range Of Tools, And 24/7 Customer Service. Sign Up For Aximtrade Login Account Today!

    ReplyDelete
  6. Search engine optimization is a highly effective digital marketing strategy for Forex Trading Seo . It is the process of optimizing a website so that it will rank higher in search engine results.

    ReplyDelete
  7. Discover professional seo services for online business. Before online trading is booming, Seo Service Provider For Forex plays an important role in the marketing strategy. Forex trading still has its own charm and attraction. People who are deeply interested in it will find their way to the right direction.

    ReplyDelete
  8. Whether you are a new trader or an experienced trader, Online Stock Broker provides all of the information you need to make an educated decision about which online broker to use. We have years of experience in this industry working alongside brokers, traders and market makers and we bring our knowledge and expertise to you with this guide.

    ReplyDelete
  9. On Our Website, You Will Find Detailed Statistics And Analysis On Vstr Stock Past Performance, Information On Current And Future Holdings, Charts, Graphs And Other Factors That Can Contribute To Your Investment Strategy. Whether You're A Seasoned Investor Or New To The Market, We Can Help You Find Facts And Figures That Are Important In Your Decision-making Process.

    ReplyDelete
  10. You'll understand the market a whole lot better with the data and graphic tools provided by our stock quote system. You'll understand how certain economic events can affect your investments, and be able to answer questions from stock market friends concerning when to buy or sell Acam Stock . You will have access to live charts, and you can receive instant notifications as stocks change in cost.

    ReplyDelete
  11. Never miss a stock price change from Acam Stock with our Live, Real Time Stock Market Overview! Most of the data is updated every 5 minutes to ensure that you are getting all of the latest Acam Stock change alerts as soon as they happen.

    ReplyDelete
  12. We have analyzed Sos Stocktwits and other stock information for you so that you can stay up-to-date on the latest Sos Stocktwits market trends.

    ReplyDelete
  13. Check The Sos Stocktwits Overview To Monitor A Stock And View Live Price Changes As They Occur, Including Volume And Share Changes. With Our Live, Real Time Stock Market Overview App, You No Longer Need To Refresh Your Browser Or Watch Multiple Computer Screens To View Real Time Stock Prices.

    ReplyDelete
  14. How many times have you found an amazing coin that you wanted to invest in, only to find out that the cost per coin is just too high? Where To Buy Ubx Coin offers cryptocurrency investors a cost effective way to get their feet wet in the market. With a set price of $1.00, Ubx Coin has made the value per coin equal the same as 1000 regular coins. Find out Where to buy Ubx Coin today!

    ReplyDelete
  15. As a new forex trader you need to know what the best brokers offers and their How To Start Forex Broker before you begin trading and investing, Use this guide to learn about trading costs, leverage and leverage limits, spreads and execution times, custodial services and market maker spreads .

    ReplyDelete
  16. Ati Testing Login will help you to choose the bestAti Testing Login online account for you. We are committed to providing excellent online recommendation for home buyers and sellers of personal information.

    ReplyDelete
  17. Login07 Is A New Forex Trading Company That Helps Traders And Investors To Find The Right Brokers And Strategies For Online Trading. Along With Broker Review And Login Details At Forex Trading Reviews We Offer Guest Post And Blog, Content Marketing Services, Building Services, Investment Guides And Much More. On Login07 You Will Also Find The Latest Press Releases, Industry News, Price Quotes That Might Effect Investment Decision. Were Ready To Help You Start Your Business.

    ReplyDelete
  18. Forex trading is one of the fastest growing markets. White Label Partnership Forex will teach you how to trade forex like a pro. It contains some of the best strategies for learning a six-figure income in your spare time with very little financial risk.

    ReplyDelete
  19. If you’ve been looking for information on what is forex seo , then tradingzy is the best place for you. We’re a digital marketing agency specializing in forex seo strategy.

    ReplyDelete
  20. Get maximum business with "Forex Seo Services. In the era of the internet, the only effective way to connect with people is online. Tradingzy is a digital marketing agency for the financial industry that specializes in increasing the traffic and conversion rate of your website. We can help grow your leads, customers and business performance with our reliable Forex digital marketing services.

    ReplyDelete
  21. Awesome article! I want people to know just how good this information is in your article. It’s interesting, compelling content. Your views are much like my own concerning this subject. note to frequency

    ReplyDelete
  22. Here are our top picks for the Best MT4 Forex Brokers In UAE . We chose only regulated and reputable brokers who have low fees and offer reliable trading platforms to their traders.

    ReplyDelete
  23. Top Forex Brokers In Malaysia Is An Online Investment Platform That Makes It Easy To Trade In Cryptocurrency, Forex And Cfds. Our Platform Is Secure, Reliable, And It Ensures High Quality Of Service. Read More Here.

    ReplyDelete