Skip to content

Commit

Permalink
Added scan.
Browse files Browse the repository at this point in the history
  • Loading branch information
hammer committed May 23, 2010
1 parent b5cee62 commit c163d71
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/pyhbase-cli
Expand Up @@ -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':
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pyhbase/connection.py
Expand Up @@ -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

58 changes: 58 additions & 0 deletions pyhbase/schema/hbase.avpr
Expand Up @@ -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",
Expand Down Expand Up @@ -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" ]
}
}
}

0 comments on commit c163d71

Please sign in to comment.