Practical Applications of hadoop and hive (iii) -- Basic Applications of hive

Source: Internet
Author: User

I have already set up the hadoop and hive environments, created a table page in hive, and loaded the data in. Now I want to count the traffic of each URL from this table and put it in another relational database or display it on the page. What should I do?

Go to the official website and check whether Java, Python, and PHP can be used for implementation. The following is a simple script written in Python.

 

From hive_service import thrifthive
From hive_service.ttypes import hiveserverexception
From Thrift import Thrift
From Thrift. Transport Import tsocket
From Thrift. Transport Import tTransport
From Thrift. Protocol import tbinaryprotocol

 

Urlcount = {}
Def getflowbyhive ():
Try:
Transport = tsocket. tsocket ('2017. *. *. 100', 219)
Transport = tTransport. tbufferedtransport (Transport)
Protocol = tbinaryprotocol. tbinaryprotocol (Transport)

Client = thrithive. Client (Protocol)
Transport. open ()
Client.exe cute ("select URL, count (*) from page group by URL ")
While (1 ):
Row = client. fetchone ()
SP = row. Split ('/t ')
If (LEN (SP) <2 ):
Continue
If (ROW = none ):
Break
Urlcount [Sp [0] = Sp [1]
Print SP [0], SP [1]
Transport. Close ()

Setting t thrift. texception, TX:
Print '% s' % (TX. Message)

 

In the 219. *. *. 200 start the hive service on the server and use it to connect programs such as Python and Java to hive. bin/hive -- service hiveserver 10001 does not support starting the execution program in the nohup background with the default port number 10000, after urlcount is complete, the URL: Count key-value pair should be stored, and you will be able to process the data in the database or display it.

Hwi is short for hive web interface and is a Web replacement solution of hive CLI. 0.7 default is built-in Hwi, CONF/hive-default.xml files are default, start Hwi service in the background

Nohup bin/hive -- service Hwi>/dev/null 2>/dev/null &

Enter http: // 10.20.151.7: 9999/Hwi/in the browser. You can view the data warehouse and run the statement.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.