Created
December 26, 2012 18:24
-
-
Save gmoothart/4382020 to your computer and use it in GitHub Desktop.
Flask script to demonstrate hbase connectivity and play around with it
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 flask import Flask | |
import happybase | |
app = Flask(__name__) | |
app.debug = True | |
@app.route("/") | |
def hello(): | |
conn = happybase.Connection('hbase') | |
conn.open() | |
try: | |
t = happybase.Table('recipients', conn) | |
# put | |
t.put('[email protected]', {'data:one': '1', 'data:two':'2', 'data:first': 'george', 'data:last':'foreman'}) | |
# multiput | |
with t.batch() as b: | |
for i in range(100): b.put('1-foo{0}@abc.com'.format(i), {'data:one': str(i), 'data:two':str(i*i), 'data:first': 'george', 'data:last':'foreman'}) | |
# get | |
r = t.row('[email protected]', ['data']) | |
# delete | |
t.delete('[email protected]') | |
# scan | |
s = t.scan(None, columns=['data'], limit=105) | |
return str(r) + "; scan count: " + str(len(list(s))) | |
finally: | |
conn.close() | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment