Class: HBase::Scoped
- Inherits:
-
Object
- Object
- HBase::Scoped
- Includes:
- Enumerable, Aggregation, Util
- Defined in:
- lib/hbase-jruby/scoped.rb,
lib/hbase-jruby/scoped/aggregation.rb
Overview
@return [HBase::Table] HBase::Table instance for this scope
Defined Under Namespace
Modules: Aggregation
Constant Summary
Constants included from Util
Util::JAVA_BYTE_ARRAY_CLASS, Util::JAVA_BYTE_ARRAY_EMPTY
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#at(ts) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified timestamp.
-
#batch(b) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified batch limit.
-
#caching(rows) ⇒ HBase::Scoped
Sets the number of rows for caching that will be passed to scanners.
-
#count(options = {}) ⇒ Fixnum, Bignum
Count the number of rows in the scope.
-
#each {|row| ... } ⇒ Object
Iterate through the scope.
-
#filter(*filters) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the filters added.
-
#get(rowkeys) ⇒ Object
Performs GET operations.
-
#limit(rows) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified row number limit.
-
#project(*columns) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified projection.
- #range(*key_range) ⇒ Object
-
#time_range(min, max) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified time range.
-
#unscope ⇒ HBase::Scope
A clean HBase::Scoped object for the same table.
-
#versions(vs) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified version number limit.
-
#while(*filters) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the additional filters which will cause early termination of scan.
-
#with_java_get {|org.apache.hadoop.hbase.client.Get| ... } ⇒ HBase::Scoped
Returns an HBase::Scoped object with the Get-customization block added The given block will be evaluated just before an actual get operation.
-
#with_java_scan {|org.apache.hadoop.hbase.client.Scan| ... } ⇒ HBase::Scoped
Returns an HBase::Scoped object with the Scan-customization block added.
Methods included from Util
append_0, from_bytes, java_bytes?, parse_column_name, to_bytes, to_typed_bytes
Methods included from Aggregation
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
11 12 13 |
# File 'lib/hbase-jruby/scoped.rb', line 11 def table @table end |
Instance Method Details
#at(ts) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified timestamp
183 184 185 |
# File 'lib/hbase-jruby/scoped.rb', line 183 def at ts spawn :@trange, time_to_long(ts) end |
#batch(b) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified batch limit
229 230 231 232 |
# File 'lib/hbase-jruby/scoped.rb', line 229 def batch b raise ArgumentError, "Invalid batch size. Must be a positive integer." unless b.is_a?(Fixnum) && b > 0 spawn :@batch, b end |
#caching(rows) ⇒ HBase::Scoped
Sets the number of rows for caching that will be passed to scanners.
83 84 85 86 |
# File 'lib/hbase-jruby/scoped.rb', line 83 def caching rows raise ArgumentError, "Invalid caching size. Must be a non-negative integer." unless rows.is_a?(Fixnum) && rows >= 0 spawn :@caching, rows end |
#count(options = {}) ⇒ Fixnum, Bignum
Count the number of rows in the scope
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hbase-jruby/scoped.rb', line 25 def count = {} = { :caching => nil, :cache_blocks => true }.merge() scan = block_given? ? filtered_scan : filtered_scan_minimum scan.setCacheBlocks [:cache_blocks] if [:caching] && (@limit.nil? || [:caching] < @limit) scan.setCaching [:caching] end cnt = 0 if block_given? iterate(scan) do |result| cnt += 1 if yield(Row.send(:new, @table, result)) end else iterate(scan) { |r| cnt += 1 } end cnt end |
#each {|row| ... } ⇒ Object
Iterate through the scope.
72 73 74 75 76 77 78 |
# File 'lib/hbase-jruby/scoped.rb', line 72 def each return enum_for(:each) unless block_given? iterate(filtered_scan) do |result| yield Row.send(:new, @table, result) end end |
#filter(*filters) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the filters added
151 152 153 |
# File 'lib/hbase-jruby/scoped.rb', line 151 def filter *filters spawn :@filters, @filters + parse_filter_input(filters) end |
#get(rowkey) ⇒ HBase::Row? #get(rowkeys) ⇒ Array<HBase::Row>
Performs GET operations
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hbase-jruby/scoped.rb', line 57 def get rowkeys case rowkeys when Array htable.get(rowkeys.map { |rk| getify rk }).map { |result| result.isEmpty ? nil : Row.send(:new, @table, result) } else result = htable.get(getify rowkeys) result.isEmpty ? nil : Row.send(:new, @table, result) end end |
#limit(rows) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified row number limit
165 166 167 168 169 170 |
# File 'lib/hbase-jruby/scoped.rb', line 165 def limit rows unless (rows.is_a?(Fixnum) && rows >= 0) || rows.nil? raise ArgumentError, "Invalid limit. Must be a non-negative integer or nil." end spawn :@limit, rows end |
#project(*columns) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified projection
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/hbase-jruby/scoped.rb', line 190 def project *columns if columns.first.is_a?(Hash) hash = columns.first unless (hash.keys - [:prefix, :range, :limit, :offset]).empty? raise ArgumentError, "Invalid projection" end if l = hash[:limit] unless l.is_a?(Fixnum) && l >= 0 raise ArgumentError, ":limit must be a non-negative integer" end end if o = hash[:offset] unless o.is_a?(Fixnum) && o >= 0 raise ArgumentError, ":offset must be a non-negative integer" end end end spawn :@project, @project + columns.map { |c| cf, cq, type = @table.lookup_schema(c) cf ? [cf, cq] : c } end |
#range(start_key, opts = {}) ⇒ HBase::Scoped #range(start_key, stop_key, opts = {}) ⇒ HBase::Scoped #range(start_stop_range, opts = {}) ⇒ HBase::Scoped #range(opts) ⇒ HBase::Scoped
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/hbase-jruby/scoped.rb', line 119 def range *key_range if (last = key_range.last).is_a?(Hash) prefixes = arrayfy(last[:prefix]).compact last = last.reject { |k, v| k == :prefix } key_range = key_range[0...-1] # defensive key_range << last unless last.empty? else prefixes = [] end if key_range[0].is_a?(Range) raise ArgumentError, "Invalid range" unless key_range.length == 1 elsif !prefixes.empty? raise ArgumentError, "Invalid range" unless [0, 1, 2].include?(key_range.length) else raise ArgumentError, "Invalid range" unless [1, 2].include?(key_range.length) end raise ArgumentError, "Invalid range" if !key_range.empty? && key_range.all? { |e| e.nil? } spawn :@range, key_range[0].is_a?(Range) ? key_range[0] : (key_range.empty? ? nil : key_range.map { |e| e.nil? ? nil : Util.to_bytes(e) }), :@prefixes, prefixes end |
#time_range(min, max) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified time range
176 177 178 |
# File 'lib/hbase-jruby/scoped.rb', line 176 def time_range min, max spawn :@trange, [min, max].map { |e| time_to_long e } end |
#unscope ⇒ HBase::Scope
A clean HBase::Scoped object for the same table
15 16 17 |
# File 'lib/hbase-jruby/scoped.rb', line 15 def unscope Scoped.send(:new, @table, @dcaching) end |
#versions(vs) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified version number limit. If not set or set to :all, all versions are fetched.
219 220 221 222 223 224 |
# File 'lib/hbase-jruby/scoped.rb', line 219 def versions vs unless vs.is_a?(Fixnum) && vs > 0 || vs == :all raise ArgumentError, "Invalid versions. Must be a positive integer or :all." end spawn :@versions, vs end |
#while(*filters) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the additional filters which will cause early termination of scan
158 159 160 |
# File 'lib/hbase-jruby/scoped.rb', line 158 def while *filters spawn :@filters, @filters + parse_filter_input(filters).map { |filter| WhileMatchFilter.new(filter) } end |
#with_java_get {|org.apache.hadoop.hbase.client.Get| ... } ⇒ HBase::Scoped
Returns an HBase::Scoped object with the Get-customization block added The given block will be evaluated just before an actual get operation. With method-chaining, multiple blocks can be registered to be evaluated sequentially.
250 251 252 253 254 |
# File 'lib/hbase-jruby/scoped.rb', line 250 def with_java_get &block raise ArgumentError, "Block not given" if block.nil? raise ArgumentError, "Invalid arity: should be 1" unless block.arity == 1 spawn :@get_cbs, @get_cbs + [block] end |
#with_java_scan {|org.apache.hadoop.hbase.client.Scan| ... } ⇒ HBase::Scoped
Returns an HBase::Scoped object with the Scan-customization block added. The given block will be evaluated just before an actual scan operation. With method-chaining, multiple blocks can be registered to be evaluated sequentially.
239 240 241 242 243 |
# File 'lib/hbase-jruby/scoped.rb', line 239 def with_java_scan &block raise ArgumentError, "Block not given" if block.nil? raise ArgumentError, "Invalid arity: should be 1" unless block.arity == 1 spawn :@scan_cbs, @scan_cbs + [block] end |