diff --git a/examples/pyhbase-cli b/examples/pyhbase-cli index 8ec3584..9927ac3 100755 --- a/examples/pyhbase-cli +++ b/examples/pyhbase-cli @@ -22,6 +22,8 @@ if __name__=="__main__": get table row [family1[:qualifier1] [family2[:qualifier2] ...]] put table row family1:qualifier1 value1 [family2:qualifier2 value2 ...] + + scan table number_of_rows """ % sys.argv[0] if len(sys.argv) <= 1 or sys.argv[1] == '--help': @@ -89,6 +91,11 @@ if __name__=="__main__": usage() sys.exit(1) print connection.put(*args) + elif cmd == 'scan': + if len(args) != 2: + usage() + sys.exit(1) + print connection.scan(*args) else: usage() sys.exit(1) diff --git a/pyhbase/connection.py b/pyhbase/connection.py index 25c9ffb..3827f85 100644 --- a/pyhbase/connection.py +++ b/pyhbase/connection.py @@ -130,3 +130,12 @@ def put(self, table, row, *column_values): # Scan # + # TODO(hammer): Figure out cleaner, more functional command-line + @retry_wrapper + def scan(self, table, number_of_rows): + params = {"table": table, "scan": {}} + scanner_id = self.requestor.request("scannerOpen", params) + results = self.requestor.request("scannerGetRows", {"scannerId": scanner_id, "numberOfRows": int(number_of_rows)}) + self.requestor.request("scannerClose", {"scannerId": scanner_id}) + return results + diff --git a/pyhbase/schema/hbase.avpr b/pyhbase/schema/hbase.avpr index 39fc9ad..c507360 100644 --- a/pyhbase/schema/hbase.avpr +++ b/pyhbase/schema/hbase.avpr @@ -164,6 +164,31 @@ "items" : "AColumnValue" } } ] + }, { + "type" : "record", + "name" : "AScan", + "fields" : [ { + "name" : "startRow", + "type" : [ "bytes", "null" ] + }, { + "name" : "stopRow", + "type" : [ "bytes", "null" ] + }, { + "name" : "columns", + "type" : [ { + "type" : "array", + "items" : "AColumn" + }, "null" ] + }, { + "name" : "timestamp", + "type" : [ "long", "null" ] + }, { + "name" : "timerange", + "type" : [ "ATimeRange", "null" ] + }, { + "name" : "maxVersions", + "type" : [ "int", "null" ] + } ] }, { "type" : "error", "name" : "AIOError", @@ -274,6 +299,39 @@ } ], "response" : "null", "errors" : [ "AIOError" ] + }, + "scannerOpen" : { + "request" : [ { + "name" : "table", + "type" : "bytes" + }, { + "name" : "scan", + "type" : "AScan" + } ], + "response" : "int", + "errors" : [ "AIOError" ] + }, + "scannerClose" : { + "request" : [ { + "name" : "scannerId", + "type" : "int" + } ], + "response" : "null", + "errors" : [ "AIOError", "AIllegalArgument" ] + }, + "scannerGetRows" : { + "request" : [ { + "name" : "scannerId", + "type" : "int" + }, { + "name" : "numberOfRows", + "type" : "int" + } ], + "response" : { + "type" : "array", + "items" : "AResult" + }, + "errors" : [ "AIOError", "AIllegalArgument" ] } } } \ No newline at end of file