RHive installation and usage

Source: Internet
Author: User

Rhive is a package that uses hive high-performance queries to expand R computing capabilities. It can easily call hql in the r environment, and can also use R objects and functions in hive. Theoretically, the data processing capacity can be expanded infinitely on the hive platform, coupled with the R environment, which is a perfect environment for Big Data Analysis and mining.

Environment Configuration

(The configuration is done by a colleague and only some details are recorded)

Rhive depends on rserve, so there are some changes when installing R:

  1. ./configure --disable-nls --enable-R-shlib
  2. make
  3. make install

Enable-r-shlib is to install R as a dynamic library, so that packages such as rserve dependent on the R dynamic library can be installed, but the disadvantage is thatPerformance drops by about 20%.

Rserve Installation

Normal R package installation:

  1. install.packages('rJava')
  2. install.packages('Rserve')

Under the rsever installation user, create a directory, create the rserv. conf file, and write ''remote enable'' to save and exit.

Run the SCP-R command to copy the rserve package installed on the master node and the rserv. conf file to all slave nodes,

  1. scp -r /data2/soft/R2.15/library/Rserve slave1:/data2/soft/R2.15/library/
  2. scp -r /data2/soft/R2.15/library/Rserve slave2:/data2/soft/R2.15/library/
  3. scp -r /data2/soft/R2.15/library/Rserve slave3:/data2/soft/R2.15/library/
  4. scp -r /data2/soft/Rserv.conf slave1:/data2/soft/
  5. scp -r /data2/soft/Rserv.conf slave2:/data2/soft/
  6. scp -r /data2/soft/Rserv.conf slave3:/data2/soft/

Start rserve on all nodes

  1. Rserve--RS-conf /data2/soft/Rserv.conf
  2. telnet slave1 6311

Telnet all slave nodes on the master node. If rsrv0103qap1 is displayed, the connection is successful.

Rhive Installation

Installation Package, create a directory on the master node and all slave nodes, and grant Read and Write Permissions

  1. R CMD INSTALL RHive_0.0-7.tar.gz
  2. cd /data2/soft/
  3. mkdir -p rhive/data

Configure environment variables for hadoop users on Master nodes and all slave nodes

  1. vi .bash_profile
  2. export RHIVE_DATA=/data2/soft/R/rhive/data

Run the SCP-R command to copy the rhive package installed on the master node to all slave nodes,

  1. scp -r /data2/soft/R2.15/library/RHive slave1:/data2/soft/R2.15/library/
  2. scp -r /data2/soft/R2.15/library/RHive slave2:/data2/soft/R2.15/library/
  3. scp -r /data2/soft/R2.15/library/RHive slave3:/data2/soft/R2.15/library/

Check whether the jar package in the HDFS file system has read and write permissions.

  1. hadoop fs -ls /rhive/lib

Finally, start the hive remote service: rhive connects to hiveserver through thrift. You need to start the background thrift service, that is, start the hive remote service on the hive client.

  1. nohup hive --service hiveserver &

Complete.

Rhive-API

Functions used to obtain table information from hive, such

  • Rhive. List. Tables: obtains the table name list. The pattern parameter (Regular Expression) is supported, similar to the show table
  • Rhive. DESC. Table: Table description. DESC table in hive
  • Rhive. exist. Table:
Simple rhive Application

Load the rhive package, connect to hive, and obtain data:

  1. library(RHive)
  2. rhive.connect(host ='host_ip')
  3. d <- rhive.query('select * from emp limit 1000')
  4. class(d)
  5. m <- rhive.block.sample(data_sku, percent =0.0001, seed =0)
  6. rhive.close()

Generally, the host has been configured in the system, so you can directlyrhive.connect()Connect. Remember to haverhive.close()Operation. The hive query statement is used to load the target data in hive to the r environment, and the returned D is a dataframe.

Actually,rhive.queryThere are many practical uses, generally hive operations can be used, such as changing scheme:

  1. rhive.query('use scheme1')
  2. rhive.query('show tables')
  3. rhive.query('drop table emp')

However, when the data volume is large, you need to userhive.big.queryAnd set the memlimit parameter.

To store objects in R to hive by creating tables, you need to use

  1. rhive.write.table(dat, tablename ='usertable', sep =',')

Then, use hive statements such as join to obtain the relevant modeling data. As a matter of fact, it should be clear to those who need it. These rhive functions are enough to be interesting.

  • NOTE 1: For other information about calling the r function in hive, no application is available yet and will be updated in the future.
  • NOTE 2:rhive.block.sampleThis function can be executed only in hive 0.8 or later.

  • Reference: rhive GitHub Project

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.