Jython-based operation of HBase

Source: Internet
Author: User

First, preface

About Jython Introduction, the direct Officer Net www.jython.org, can get detailed information, here only to introduce some of the methods of Jython operation HBase, in essence and in Java operation HBase almost, but the syntax changed to Python

Second, the environment

HBase version: 0.98.6.1

Hadoop version: 2.5.2

Jython Version: 2.7

Three, Jython installation configuration

1 installation

About Hbase&hadoop installation configuration is not introduced here, the main introduction of Jython installation configuration, in fact, the installation is very simple, execute a command on OK

Java-jar jython-installer-2.7. 0. jar-d/data/jython27

-D: Specify the Jython installation directory

2 configuration

There are three main aspects involved in Jython configuration: hbase classpath, System environment variables (ease of operation) and HBase classpath (allow Jython to find the lib of HBase)

1) hbase classpath settings

You need to configure the following environment variables in hbase-env.sh:

Export java_home=/data/jdk1.7. 0_51export hadoop_home=/data/hadoopexporthbase_home =/data/  Hbaseexport hadoop_conf_dir=/data/hadoop/etc/hadoopexport hbase_conf_dir=/data/hbase/  Confexport zoocfgdir=/data/zookeeper-3.4.6/confexport CLASSPATH=.: $JAVA _home/lib: $JAVA _home/jre/ Lib: $CLASSPATHexport hadoop_classpath=.: $HBASE _home/*: $HBASE _conf_dir: $HADOOP _classpathexport HBASE _classpath= $HBASE _conf_dir: $ZOOCFGDIR

2) The Jython system environment variable is set as follows

Add the following line in/ETC/BASHRC, or ~/.BASHRC, or ~/.bash_profile file

Export jython_home=/data/jython27export jython_bin= $JYTHON _home/binexport PATH= $JYTHON _bin:$ PATH

3) Jython classpath settings

If this step is not set, when you start the Jython script, you are prompted to find an error with the HBase-related module, so you need to add hbase classpath in the Jython startup script file, namely, to edit Jython under the Jython directory bin, add the following in the appropriate location:

if [!-Z "$CLASSPATH"];then    classpath= $CLASSPATH:/data/hbase/lib/*    cp= $CP: $CLASSPATHfi

Note: Add the location below the cp= $JYTHON _home/jython.jar, as shown in

Iv. Jython Operation HBase Script

This script primarily creates an HBase table and sets the relevant parameters

ImportJava.langImportJava.util fromOrg.apache.hadoop.hbase.clientImportHbaseadmin,htable,put,get fromOrg.apache.hadoop.hbaseImportHregioninfo,servername fromOrg.apache.hadoop.hbase.catalogImportMetareader,catalogtracker fromOrg.apache.hadoop.hbaseImporthbaseconfiguration, Htabledescriptor, Hcolumndescriptor, hconstants fromOrg.apache.hadoop.hbase.utilImportBytes,writables fromOrg.apache.hadoop.hbase.io.compressImportCompression fromOrg.apache.hadoop.hbase.regionserverImportBloomtype fromOrg.apache.hadoop.hbase.io.encodingImportdatablockencoding#global variableconf,admin=None,noneclassCreateTable (object):def __init__(self,conf,admin): Self.base_dir= Os.path.abspath (Os.path.join (Os.path.dirname (__file__) , Os.pardir) self.logname='%s/log/create_table.log'%Self.base_dir Self.logger=Logger (). GetLogger (self.logname) self.conf=conf self.admin=Admindefcreatetable (self,tablename):desc =htabledescriptor (tableName) HCD= Hcolumndescriptor ("I") Hcd.setcompressiontype (Compression.Algorithm.GZ); Hcd.setblocksize (64*1024) hcd.setmaxversions (1) hcd.setminversions (0) hcd.setinmemory (False) hcd.setblockcacheenabled (True) hcd.setbloom FilterType (Bloomtype.row) hcd.setdatablockencoding (datablockencoding.diff) hcd.setscope (0) de Sc.addfamily (HCD) desc.setmaxfilesize (5368709120) Desc.setvalue (desc. Split_policy,'Org.apache.hadoop.hbase.regionserver.DisabledRegionSplitPolicy')        ifself.admin.tableExists (tableName): self.admin.disableTable (TableName) self.admin.deleteTable (ta Blename) self.admin.createTable (DESC)defGetTableInfo (self,tablename): Desc=admin.gettabledescriptor (tableName)returndesc.tostring ()if __name__=='__main__': Conf=hbaseconfiguration () admin=hbaseadmin (conf) CT=createtable (conf,admin) ct.createtable ('Test')    PrintCt.gettableinfo ('Test')

Jython-based operation of HBase

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.