Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added put method.

  • Loading branch information...
commit 9e9b4e37774012e1fa7dcb4157f426ed9816f5fe 1 parent c706197
Jeff Hammerbacher hammer authored
7 examples/pyhbase-cli
View
@@ -18,6 +18,8 @@ if __name__=="__main__":
disable_table table
get table row [family1[:qualifier1] [family2[:qualifier2] ...]]
+
+ put table row family1:qualifier1 value1 [family2:qualifier2 value2 ...]
""" % sys.argv[0]
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
@@ -70,6 +72,11 @@ if __name__=="__main__":
usage()
sys.exit(1)
print connection.get(*args)
+ elif cmd == 'put':
+ if len(args) < 4 or not len(args) % 2 == 0:
+ usage()
+ sys.exit(1)
+ print connection.put(*args)
else:
usage()
sys.exit(1)
17 pyhbase/connection.py
View
@@ -47,6 +47,8 @@ def make_connection(self, retry=2):
exceptionType, exception, tracebackInfo = sys.exc_info()
raise exception
+ # TODO(hammer): classify these methods like the HBase shell
+
#
# Metadata
#
@@ -84,11 +86,11 @@ def disable_table(self, table):
# Get
#
+ # TODO(hammer): Figure out how to get binary keys
+ # TODO(hammer): Do this parsing logic in pyhbase-cli?
@retry_wrapper
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
@@ -99,6 +101,17 @@ def get(self, table, row, *columns):
# Put
#
+ # TODO(hammer): Figure out how to incorporate timestamps
+ # TODO(hammer): Do this parsing logic in pyhbase-cli?
+ @retry_wrapper
+ def put(self, table, row, *column_values):
+ put = {"row": row}
+ column_values = [{"family": column.split(":")[0], "qualifier": column.split(":")[1], "value": value}
+ for column, value in zip(column_values[::2], column_values[1::2])]
+ put["columnValues"] = column_values
+ params = {"table": table, "put": put}
+ return self.requestor.request("put", params)
+
#
# Delete
#
40 pyhbase/schema/hbase.avpr
View
@@ -136,6 +136,35 @@
"type" : [ "int", "null" ]
} ]
}, {
+ "type" : "record",
+ "name" : "AColumnValue",
+ "fields" : [ {
+ "name" : "family",
+ "type" : "bytes"
+ }, {
+ "name" : "qualifier",
+ "type" : "bytes"
+ }, {
+ "name" : "value",
+ "type" : "bytes"
+ }, {
+ "name" : "timestamp",
+ "type" : [ "long", "null" ]
+ } ]
+ }, {
+ "type" : "record",
+ "name" : "APut",
+ "fields" : [ {
+ "name" : "row",
+ "type" : "bytes"
+ }, {
+ "name" : "columnValues",
+ "type" : {
+ "type" : "array",
+ "items" : "AColumnValue"
+ }
+ } ]
+ }, {
"type" : "error",
"name" : "AIOError",
"fields" : [ {
@@ -215,6 +244,17 @@
} ],
"response" : "AResult",
"errors" : [ "AIOError" ]
+ },
+ "put" : {
+ "request" : [ {
+ "name" : "table",
+ "type" : "bytes"
+ }, {
+ "name" : "put",
+ "type" : "APut"
+ } ],
+ "response" : "null",
+ "errors" : [ "AIOError" ]
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.