HBASE-13721 - Improve shell scan performances when using LIMIT (JMS)

This commit is contained in:
ramkrishna 2015-05-20 22:20:35 +05:30
parent 181ec60510
commit fd15bd13db
1 changed files with 7 additions and 5 deletions

View File

@ -425,6 +425,7 @@ EOF
consistency = args[CONSISTENCY]
# Normalize column names
columns = [columns] if columns.class == String
limit = args["LIMIT"] || -1
unless columns.kind_of?(Array)
raise ArgumentError.new("COLUMNS must be specified as a String or an Array")
end
@ -460,6 +461,7 @@ EOF
scan.setMaxVersions(versions) if versions > 1
scan.setTimeRange(timerange[0], timerange[1]) if timerange
scan.setRaw(raw)
scan.setCaching(limit) if limit > 0
set_attributes(scan, attributes) if attributes
set_authorizations(scan, authorizations) if authorizations
scan.setConsistency(org.apache.hadoop.hbase.client.Consistency.valueOf(consistency)) if consistency
@ -479,7 +481,7 @@ EOF
def _scan_internal(args = {})
raise(ArgumentError, "Arguments should be a Hash") unless args.kind_of?(Hash)
limit = args.delete("LIMIT") || -1
limit = args["LIMIT"] || -1
maxlength = args.delete("MAXLENGTH") || -1
count = 0
res = {}
@ -492,10 +494,6 @@ EOF
# Iterate results
while iter.hasNext
if limit > 0 && count >= limit
break
end
row = iter.next
key = org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow)
@ -516,6 +514,10 @@ EOF
# One more row processed
count += 1
if limit > 0 && count >= limit
# If we reached the limit, exit before the next call to hasNext
break
end
end
return ((block_given?) ? count : res)