junegunn commented on code in PR #6656:
URL: https://github.com/apache/hbase/pull/6656#discussion_r1942268264
##########
hbase-shell/src/main/ruby/hbase/table.rb:
##########
@@ -321,24 +321,21 @@ def _append_internal(row, column, value, args = {})
def _count_internal(interval = 1000, scan = nil, cacheBlocks=false)
raise(ArgumentError, 'Scan argument should be
org.apache.hadoop.hbase.client.Scan') \
unless scan.nil? || scan.is_a?(org.apache.hadoop.hbase.client.Scan)
- # We can safely set scanner caching with the first key only filter
- if scan.nil?
- scan = org.apache.hadoop.hbase.client.Scan.new
- scan.setCacheBlocks(cacheBlocks)
- scan.setCaching(10)
- scan.setFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter.new)
- else
- scan.setCacheBlocks(cacheBlocks)
- filter = scan.getFilter
- firstKeyOnlyFilter =
org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter.new
- if filter.nil?
- scan.setFilter(firstKeyOnlyFilter)
- else
- firstKeyOnlyFilter.setReversed(filter.isReversed)
- scan.setFilter(org.apache.hadoop.hbase.filter.FilterList.new(filter,
firstKeyOnlyFilter))
- end
+ scan ||= org.apache.hadoop.hbase.client.Scan.new
+ scan.setCacheBlocks(cacheBlocks)
+
+ # Optimize counting by using FirstKeyOnlyFilter and KeyOnlyFilter
+ filters = [
+ org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter.new,
+ org.apache.hadoop.hbase.filter.KeyOnlyFilter.new
Review Comment:
> Why not only use KeyOnlyFilter?
A record can have many number of columns. If we only use KeyOnlyFilter,
we'll fetch that many cells. Their values will be empty, but they're still
unnecessary for counting, we just need one cell.
```sh
# No filter
R1: CF:CQ1="foo" CF:CQ2="bar" CF:CQ3="baz"
# KeyOnlyFilter
R1: CF:CQ1="" CF:CQ2="" CF:CQ3=""
# FirstKeyOnlyFilter
R1: CF:CQ1="foo"
# FirstKeyOnlyFilter + KeyOnlyFilter
R1: CF:CQ1=""
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]