Skip to content
Browse files

Made get more functional, updated list_tables, added create_table.

  • Loading branch information...
1 parent eef8e3d commit c70619760cf9f44f5e31635fa68b52b5f1316a8d @hammer hammer committed
Showing with 124 additions and 13 deletions.
  1. +11 −5 examples/pyhbase-cli
  2. +18 −5 pyhbase/connection.py
  3. +94 −2 pyhbase/schema/hbase.avpr
  4. +1 −1 setup.py
View
16 examples/pyhbase-cli
@@ -10,13 +10,14 @@ if __name__=="__main__":
Usage: %s [-h host[:port]] command [arg1 [arg2...]]
Commands:
- show_tables
+ list_tables
is_table_enabled table
+ create_table table [family1 [family2 ...]]
enable_table table
disable_table table
- get table row
+ get table row [family1[:qualifier1] [family2[:qualifier2] ...]]
""" % sys.argv[0]
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
@@ -39,16 +40,21 @@ if __name__=="__main__":
connection = HBaseConnection(host, port)
- if cmd == 'show_tables':
+ if cmd == 'list_tables':
if len(args) != 0:
usage()
sys.exit(1)
- print connection.show_tables(*args)
+ print connection.list_tables(*args)
elif cmd == 'is_table_enabled':
if len(args) != 1:
usage()
sys.exit(1)
print connection.is_table_enabled(*args)
+ elif cmd == 'create_table':
+ if len(args) < 1:
+ usage()
+ sys.exit(1)
+ print connection.create_table(*args)
elif cmd == 'enable_table':
if len(args) != 1:
usage()
@@ -60,7 +66,7 @@ if __name__=="__main__":
sys.exit(1)
print connection.disable_table(*args)
elif cmd == 'get':
- if len(args) != 2:
+ if len(args) < 2:
usage()
sys.exit(1)
print connection.get(*args)
View
23 pyhbase/connection.py
@@ -52,9 +52,9 @@ def make_connection(self, retry=2):
#
@retry_wrapper
- def show_tables(self):
- """Grab table names."""
- return self.requestor.request("getTableNames", {})
+ def list_tables(self):
+ """Grab table information."""
+ return self.requestor.request("listTables", {})
@retry_wrapper
def is_table_enabled(self, table):
@@ -66,6 +66,13 @@ def is_table_enabled(self, table):
#
@retry_wrapper
+ def create_table(self, table, *families):
+ table_descriptor = {"name": table}
+ families = [{"name": family} for family in families]
+ if families: table_descriptor["families"] = families
+ return self.requestor.request("createTable", {"table": table_descriptor})
+
+ @retry_wrapper
def enable_table(self, table):
return self.requestor.request("enableTable", {"table": table})
@@ -78,8 +85,14 @@ def disable_table(self, table):
#
@retry_wrapper
- def get(self, table, row):
- params = {"table": table, "get": {"row": row}}
+ def get(self, table, row, *columns):
+ get = {"row": row}
+
+ # from my upcoming book, "how to abuse python for recovering perl addicts"
+ columns = [len(column) > 1 and {"family": column[0], "qualifier": column[1]} or {"family": column[0]}
+ for column in map(lambda s: s.split(":"), columns)]
+ if columns: get["columns"] = columns
+ params = {"table": table, "get": get}
return self.requestor.request("get", params)
#
View
96 pyhbase/schema/hbase.avpr
@@ -2,6 +2,69 @@
"protocol" : "HBase",
"namespace" : "org.apache.hadoop.hbase.avro.generated",
"types" : [ {
+ "type" : "enum",
+ "name" : "ACompressionAlgorithm",
+ "symbols" : [ "LZO", "GZ", "NONE" ]
+ }, {
+ "type" : "record",
+ "name" : "AFamilyDescriptor",
+ "fields" : [ {
+ "name" : "name",
+ "type" : "bytes"
+ }, {
+ "name" : "compression",
+ "type" : [ "ACompressionAlgorithm", "null" ]
+ }, {
+ "name" : "maxVersions",
+ "type" : [ "int", "null" ]
+ }, {
+ "name" : "blocksize",
+ "type" : [ "int", "null" ]
+ }, {
+ "name" : "inMemory",
+ "type" : [ "boolean", "null" ]
+ }, {
+ "name" : "timeToLive",
+ "type" : [ "int", "null" ]
+ }, {
+ "name" : "blockCacheEnabled",
+ "type" : [ "boolean", "null" ]
+ } ]
+ }, {
+ "type" : "record",
+ "name" : "ATableDescriptor",
+ "fields" : [ {
+ "name" : "name",
+ "type" : "bytes"
+ }, {
+ "name" : "families",
+ "type" : [ {
+ "type" : "array",
+ "items" : "AFamilyDescriptor"
+ }, "null" ]
+ }, {
+ "name" : "maxFileSize",
+ "type" : [ "long", "null" ]
+ }, {
+ "name" : "memStoreFlushSize",
+ "type" : [ "long", "null" ]
+ }, {
+ "name" : "rootRegion",
+ "type" : [ "boolean", "null" ]
+ }, {
+ "name" : "metaRegion",
+ "type" : [ "boolean", "null" ]
+ }, {
+ "name" : "metaTable",
+ "type" : [ "boolean", "null" ]
+ }, {
+ "name" : "readOnly",
+ "type" : [ "boolean", "null" ]
+ }, {
+ "name" : "deferredLogFlush",
+ "type" : [ "boolean", "null" ]
+ } ]
+ }, {
"type" : "record",
"name" : "AColumn",
"fields" : [ {
@@ -79,8 +142,37 @@
"name" : "message",
"type" : "string"
} ]
+ }, {
+ "type" : "error",
+ "name" : "AIllegalArgument",
+ "fields" : [ {
+ "name" : "message",
+ "type" : "string"
+ } ]
+ }, {
+ "type" : "error",
+ "name" : "ATableExists",
+ "fields" : [ {
+ "name" : "message",
+ "type" : "string"
+ } ]
+ }, {
+ "type" : "error",
+ "name" : "AMasterNotRunning",
+ "fields" : [ {
+ "name" : "message",
+ "type" : "string"
+ } ]
} ],
"messages" : {
+ "createTable" : {
+ "request" : [ {
+ "name" : "table",
+ "type" : "ATableDescriptor"
+ } ],
+ "response" : "null",
+ "errors" : [ "AIOError", "AIllegalArgument", "ATableExists", "AMasterNotRunning" ]
+ },
"enableTable" : {
"request" : [ {
"name" : "table",
@@ -105,11 +197,11 @@
"response" : "boolean",
"errors" : [ "AIOError" ]
},
- "getTableNames" : {
+ "listTables" : {
"request" : [ ],
"response" : {
"type" : "array",
- "items" : "bytes"
+ "items" : "ATableDescriptor"
},
"errors" : [ "AIOError" ]
},
View
2 setup.py
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
setup(name="PyHBase",
- version='0.0.3',
+ version='0.0.5',
description="High-level Python interface to HBase",
url="http://github.com/hammer/pyhbase/",
packages=['pyhbase'],

0 comments on commit c706197

Please sign in to comment.
Something went wrong with that request. Please try again.