Wednesday, December 14, 2016

Connecting to hbase using Python




  • Connecting hbase by importing a package:
    • Source: https://media.readthedocs.org/pdf/happybase/latest/happybase.pdf ---- it is beautiful document that talks about hbase connection using python.
    • Source:#http://stackoverflow.com/questions/15808717/connecting-standalone-hbase-from-python
    • Script: 
      • import happybase
      • connection = happybase.Connection('localhost', autoconnect=False)
      • connection.open()
    • Source: http://stackoverflow.com/questions/28456422/writing-to-hbase-table-from-python-happybase?rq=1
  • Connecting hbase using subprocess methods and extract data using get_value():
    • Status Success
    • Date: 11/3/2017
    • Script:
      • import csv
      • import json
      • import subprocess
      • import re
      • import pycurl
      • import StringIO
      • p1 = subprocess.Popen(["echo", 'get "%s","%s"' % (<table_name>,<unique_key>)], stdout=subprocess.PIPE)
      • p2 = subprocess.Popen(["hbase", "shell"], stdin=p1.stdout, stdout=subprocess.PIPE)
      • op_str=p2.communicate()[0]
      • column_value=get_value(op_str, <column_family>, <column_name>)
      • print column_value

No comments:

Post a Comment