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 ⇒ Fixnum, Bignum
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
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
174 175 176 |
# File 'lib/hbase-jruby/scoped.rb', line 174 def at ts spawn :@trange, time_to_long(ts) end |
#batch(b) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified batch limit
215 216 217 218 |
# File 'lib/hbase-jruby/scoped.rb', line 215 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 ⇒ Fixnum, Bignum
Number of rows in the scope
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hbase-jruby/scoped.rb', line 21 def count cnt = 0 begin if block_given? scanner = htable.getScanner(filtered_scan) scanner.each do |result| cnt += 1 if yield(Result.send(:new, result)) end else scanner = htable.getScanner(filtered_scan_minimum) scanner.each { cnt += 1 } end ensure scanner.close if scanner end cnt end |
#each {|row| ... } ⇒ Object
Iterate through the scope.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/hbase-jruby/scoped.rb', line 65 def each if block_given? begin scanner = htable.getScanner(filtered_scan) scanner.each do |result| yield Result.send(:new, result) end ensure scanner.close if scanner end else self end end |
#filter(*filters) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the filters added
144 145 146 |
# File 'lib/hbase-jruby/scoped.rb', line 144 def filter *filters spawn :@filters, @filters + parse_filter_input(filters) end |
#get(rowkey) ⇒ HBase::Result? #get(rowkeys) ⇒ Array<HBase::Result>
Performs GET operations
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hbase-jruby/scoped.rb', line 50 def get rowkeys case rowkeys when Array htable.get(rowkeys.map { |rk| getify rk }).map { |result| result.isEmpty ? nil : Result.new(result) } else result = htable.get(getify rowkeys) result.isEmpty ? nil : Result.new(result) end end |
#limit(rows) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified row number limit
158 159 160 161 |
# File 'lib/hbase-jruby/scoped.rb', line 158 def limit rows raise ArgumentError, "Invalid limit. Must be a non-negative integer." unless rows.is_a?(Fixnum) && rows >= 0 spawn :@limit, rows end |
#project(*columns) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified projection
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/hbase-jruby/scoped.rb', line 181 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 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 |
# File 'lib/hbase-jruby/scoped.rb', line 119 def range *key_range if key_range.last.is_a?(Hash) prefixes = arrayfy(key_range.last[:prefix]).compact raise ArgumentError, "Invalid range. Unknown option(s) specified." unless (key_range.last.keys - [:prefix]).empty? key_range = key_range[0...-1] end if prefixes 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 spawn :@range, key_range[0].is_a?(Range) ? key_range[0] : (key_range.empty? ? nil : key_range), :@prefixes, prefixes || [] end |
#time_range(min, max) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified time range
167 168 169 |
# File 'lib/hbase-jruby/scoped.rb', line 167 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) end |
#versions(vs) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the specified version number limit. If not set, all versions of each value are fetched by default.
207 208 209 210 |
# File 'lib/hbase-jruby/scoped.rb', line 207 def versions vs raise ArgumentError, "Invalid versions. Must be a positive integer." unless vs.is_a?(Fixnum) && vs > 0 spawn :@versions, vs end |
#while(*filters) ⇒ HBase::Scoped
Returns an HBase::Scoped object with the additional filters which will cause early termination of scan
151 152 153 |
# File 'lib/hbase-jruby/scoped.rb', line 151 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.
236 237 238 239 240 |
# File 'lib/hbase-jruby/scoped.rb', line 236 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.
225 226 227 228 229 |
# File 'lib/hbase-jruby/scoped.rb', line 225 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 |