Friday 21 August 2015

Connect to Hbase using Python Code and happybase

Step 1 : pip install happybase

Step 2 :

import happybase

#Pass public virtual IP, you can find it in Azure VM dashboard
connection = happybase.Connection('137.135.XX.XXX')

#Snippet to create table

#connection.create_table(
#mytablefrompythoncode',
#{'cf1': dict(max_versions=10),
#'cf2': dict(max_versions=1, block_cache_enabled=False),
#'cf3': dict(), # use defaults
#}
#)

#Print available tables
print connection.tables()
#Creating an instance
table = connection.table('mytablefrompythoncode')

Step 3 : hbase thrift start -threadpool (in Hortonworks Linux Machine)

Step 4 : To invoke this .py code from Linux, just copy the .py script to Linux local using WinScp or any tool and in command line type:
cd /Path_where_code_is
python xxxxxxxx.py

No comments:

Post a Comment