Using HBase with Jython

I started to play with HBase recently and decided to keep a log of what worked for me.
HBase version: hbase-0.90.2
Jython version: Jython 2.5.2

1. Install Jython, HBase
2. Setting up the classpath for hbase. The commands described on the HBase wiki worked fine for me with some minor changes.

-bash-4.1$ cd hbase-0.90.2

start hbase:

-bash-4.1$ ./bin/

checkout classpath:

-bash-4.1$ ps auwx|grep java|grep org.apache.hadoop.hbase.master.HMaster|sed -r "s/.+?classpath //" | sed -r "s/ .+?//"

copy the classpath and

-bash-4.1$ export CLASSPATH=$coppied_class_path

3. Start jyphon. Since it’s quite a long line, I just made an alias for it:

-bash-4.1$ alias pyhbase='HBASE_OPTS="-Dpython.path=$JYTHON_HOME" HBASE_CLASSPATH=$JYTHON_HOME/jython.jar $HBASE_HOME/bin/hbase org.python.util.jython'

where the $JYTHON_HOME, $HBASE_HOME, as well as the $CLASSPATH and the alias can be stored in the ~/.profile file (for bash).

The jython shell appears:

-bash-4.1$ pyhbase
Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_20
Type "help", "copyright", "credits" or "license" for more information.

To run a jython script:

-bash-4.1$ pyhbase jython_script

Useful links: (quick start with HBase) (more complicated setting up for HBase) (Using Jython to interact with HBase)


One thought on “Using HBase with Jython

  1. Nice writeup! Jython makes for a great interactive shell to work with HBase.

    One tip — instead of parsing out the classpath from ps output, you can simply do:

    export CLASSPATH=`$HBASE_HOME/bin/hbase classpath`

    The “classpath” argument outputs the classpath as setup by the HBase scripts.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s