Created
December 30, 2017 13:17
-
-
Save email2liyang/1f08b9f845ef298d86095cfce17369ba to your computer and use it in GitHub Desktop.
an hbase rest client snip to insert and load data from hbase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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