Skip to content

Instantly share code, notes, and snippets.

@email2liyang
Created December 30, 2017 13:17
Show Gist options
  • Save email2liyang/1f08b9f845ef298d86095cfce17369ba to your computer and use it in GitHub Desktop.
Save email2liyang/1f08b9f845ef298d86095cfce17369ba to your computer and use it in GitHub Desktop.
an hbase rest client snip to insert and load data from hbase
from starbase import Connection
c = Connection("127.0.0.1","8000")
ratings = c.table("ratings")
if( ratings.exists()):
print("Dropping existing table \n")
ratings.drop()
ratings.create("rating")
print("parsing files")
ratingFile = open("/Users/ivan/Desktop/u.data","r")
batch = ratings.batch()
for line in ratingFile:
(userId, movieId,raging,timestamp) = line.split()
batch.update(userId,{'rating':{movieId: raging}})
ratingFile.close()
print("commit to hbase via rest")
batch.commit(finalize=True)
print("get back rating for some users \n")
print("Rating for user 1 is \n")
print(ratings.fetch("1"))
print("Rating for user 33 is \n")
print(ratings.fetch("33"))
ratings.drop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment