Class: HBase::Table
- Inherits:
-
Object
- Object
- HBase::Table
- Includes:
- Enumerable, Admin, Scoped::Aggregation::Admin
- Defined in:
- lib/hbase-jruby/table.rb
Overview
@return [org.apache.hadoop.conf.Configuration]
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#add_coprocessor!(class_name, props = {}) ⇒ Object
Adds the table coprocessor to the table.
-
#add_family!(name, opts) ⇒ nil
Adds the column family.
-
#alter!(props) ⇒ nil
Alters the table.
-
#alter_family!(name, opts) ⇒ nil
Alters the column family.
-
#close ⇒ nil
Closes the table and returns HTable object back to the HTablePool.
- #create!(desc, props = {}) ⇒ Object
- #delete(*args) ⇒ Object
-
#delete_family!(name) ⇒ nil
Removes the column family.
-
#descriptor ⇒ org.apache.hadoop.hbase.client.UnmodifyableHTableDescriptor
Returns a read-only org.apache.hadoop.hbase.HTableDescriptor object.
-
#disable! ⇒ nil
Disables the table.
-
#disabled? ⇒ true, false
Checks if the table is disabled.
-
#drop! ⇒ nil
Drops the table.
-
#each {|HBase::Result| ... } ⇒ HBase::Scoped
Scan through the table.
-
#enable! ⇒ nil
Enables the table.
-
#enabled? ⇒ true, false
Checks if the table is enabled.
-
#exists? ⇒ true, false
Checks if the table of the name exists.
-
#has_coprocessor?(class_name) ⇒ true, false
Return if the table has the coprocessor of the given class name.
-
#htable ⇒ org.apache.hadoop.hbase.client.HTable
Returns the underlying org.apache.hadoop.hbase.client.HTable object (local to current thread).
- #increment(rowkey, *args) ⇒ Object
-
#inspect ⇒ String
Returns table description.
- #put(*args) ⇒ Object
-
#remove_coprocessor!(name) ⇒ nil
Removes the coprocessor from the table.
-
#truncate! ⇒ nil
Truncates the table by dropping it and recreating it.
Methods included from Scoped::Aggregation::Admin
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/hbase-jruby/table.rb', line 11 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/hbase-jruby/table.rb', line 10 def name @name end |
Instance Method Details
#add_coprocessor!(class_name, props = {}) ⇒ Object
Adds the table coprocessor to the table
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/hbase-jruby/table.rb', line 173 def add_coprocessor! class_name, props = {} with_admin do |admin| while_disabled(admin) do htd = admin.get_table_descriptor(@name.to_java_bytes) if props.empty? htd.addCoprocessor class_name else path, priority, params = props.values_at :path, :priority, :params params = Hash[ params.map { |k, v| [k.to_s, v.to_s] } ] htd.addCoprocessor class_name, path, priority || Coprocessor::PRIORITY_USER, params end admin.modifyTable @name.to_java_bytes, htd wait_async_admin(admin) end end end |
#add_family!(name, opts) ⇒ nil
Adds the column family
133 134 135 136 137 138 139 140 |
# File 'lib/hbase-jruby/table.rb', line 133 def add_family! name, opts with_admin do |admin| while_disabled(admin) do admin.addColumn @name, hcd(name.to_s, opts) wait_async_admin(admin) end end end |
#alter!(props) ⇒ nil
Alters the table
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/hbase-jruby/table.rb', line 118 def alter! props with_admin do |admin| htd = admin.get_table_descriptor(@name.to_java_bytes) patch_table_descriptor! htd, props while_disabled(admin) do admin.modifyTable @name.to_java_bytes, htd wait_async_admin(admin) end end end |
#alter_family!(name, opts) ⇒ nil
Alters the column family
146 147 148 149 150 151 152 153 |
# File 'lib/hbase-jruby/table.rb', line 146 def alter_family! name, opts with_admin do |admin| while_disabled(admin) do admin.modifyColumn @name, hcd(name.to_s, opts) wait_async_admin(admin) end end end |
#close ⇒ nil
Closes the table and returns HTable object back to the HTablePool.
25 26 27 28 29 30 |
# File 'lib/hbase-jruby/table.rb', line 25 def close Thread.current[:htable] ||= {} ht = Thread.current[:htable].delete(@name) ht.close if ht nil end |
#create!(column_family_name, props = {}) ⇒ nil #create!(column_family_hash, props = {}) ⇒ nil #create!(table_descriptor) ⇒ nil
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hbase-jruby/table.rb', line 82 def create! desc, props = {} todo = nil with_admin do |admin| raise RuntimeError, 'Table already exists' if admin.tableExists(@name) case desc when HTableDescriptor patch_table_descriptor! desc, props admin.createTable desc when Symbol, String todo = lambda { create!({desc => {}}, props) } when Hash htd = HTableDescriptor.new(@name.to_java_bytes) patch_table_descriptor! htd, props desc.each do |name, opts| htd.addFamily hcd(name, opts) end admin.createTable htd else raise ArgumentError, 'Invalid table description' end end todo.call if todo # Avoids mutex relocking end |
#delete(rowkey) ⇒ nil #delete(rowkey, column_family) ⇒ nil #delete(rowkey, column) ⇒ nil #delete(rowkey, column, timestamp) ⇒ nil #delete(*delete_specs) ⇒ nil
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/hbase-jruby/table.rb', line 315 def delete *args specs = args.first.is_a?(Array) ? args : [args] htable.delete specs.map { |spec| rowkey, cfcq, *ts = spec cf, cq = Util.parse_column_name(cfcq) if cfcq Delete.new(Util.to_bytes rowkey).tap { |del| if !ts.empty? ts.each do |t| del.deleteColumn cf, cq, t end elsif cq # Delete all versions del.deleteColumns cf, cq elsif cf del.deleteFamily cf end } } end |
#delete_family!(name) ⇒ nil
Removes the column family
158 159 160 161 162 163 164 165 |
# File 'lib/hbase-jruby/table.rb', line 158 def delete_family! name with_admin do |admin| while_disabled(admin) do admin.deleteColumn @name, name.to_s wait_async_admin(admin) end end end |
#descriptor ⇒ org.apache.hadoop.hbase.client.UnmodifyableHTableDescriptor
Returns a read-only org.apache.hadoop.hbase.HTableDescriptor object
19 20 21 |
# File 'lib/hbase-jruby/table.rb', line 19 def descriptor htable.get_table_descriptor end |
#disable! ⇒ nil
Disables the table
225 226 227 228 229 |
# File 'lib/hbase-jruby/table.rb', line 225 def disable! with_admin do |admin| admin.disableTable @name if admin.isTableEnabled(@name) end end |
#disabled? ⇒ true, false
Checks if the table is disabled
46 47 48 |
# File 'lib/hbase-jruby/table.rb', line 46 def disabled? !enabled? end |
#drop! ⇒ nil
Drops the table
241 242 243 244 245 246 247 248 249 |
# File 'lib/hbase-jruby/table.rb', line 241 def drop! with_admin do |admin| raise RuntimeError, 'Table does not exist' unless admin.tableExists @name admin.disableTable @name if admin.isTableEnabled(@name) admin.deleteTable @name close end end |
#each {|HBase::Result| ... } ⇒ HBase::Scoped
Scan through the table
370 371 372 373 374 375 376 |
# File 'lib/hbase-jruby/table.rb', line 370 def each if block_given? Scoped.send(:new, self).each { |r| yield r } else Scoped.send(:new, self) end end |
#enable! ⇒ nil
Enables the table
217 218 219 220 221 |
# File 'lib/hbase-jruby/table.rb', line 217 def enable! with_admin do |admin| admin.enableTable @name unless admin.isTableEnabled(@name) end end |
#enabled? ⇒ true, false
Checks if the table is enabled
40 41 42 |
# File 'lib/hbase-jruby/table.rb', line 40 def enabled? with_admin { |admin| admin.isTableEnabled(@name) } end |
#exists? ⇒ true, false
Checks if the table of the name exists
34 35 36 |
# File 'lib/hbase-jruby/table.rb', line 34 def exists? with_admin { |admin| admin.tableExists @name } end |
#has_coprocessor?(class_name) ⇒ true, false
Return if the table has the coprocessor of the given class name
211 212 213 |
# File 'lib/hbase-jruby/table.rb', line 211 def has_coprocessor? class_name descriptor.hasCoprocessor(class_name) end |
#htable ⇒ org.apache.hadoop.hbase.client.HTable
Returns the underlying org.apache.hadoop.hbase.client.HTable object (local to current thread)
380 381 382 383 384 |
# File 'lib/hbase-jruby/table.rb', line 380 def htable # @htable ||= @pool.get_table(@name) (local_htables = Thread.current[:htable] ||= {})[@name] || (local_htables[@name] = @pool.get_table(@name)) end |
#increment(rowkey, column, by) ⇒ Fixnum #increment(rowkey, column_by_hash) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/hbase-jruby/table.rb', line 351 def increment rowkey, *args if args.first.is_a?(Hash) cols = args.first htable.increment Increment.new(Util.to_bytes rowkey).tap { |inc| cols.each do |col, by| cf, cq = Util.parse_column_name(col) inc.addColumn cf, cq, by end } else col, by = args cf, cq = Util.parse_column_name(col) htable.incrementColumnValue Util.to_bytes(rowkey), cf, cq, by || 1 end end |
#inspect ⇒ String
Returns table description
388 389 390 391 392 393 394 395 |
# File 'lib/hbase-jruby/table.rb', line 388 def inspect if exists? htable.get_table_descriptor.to_s else # FIXME "{NAME => '#{@name}'}" end end |
#put(rowkey, data) ⇒ Fixnum #put(data) ⇒ Fixnum
269 270 271 272 273 274 275 |
# File 'lib/hbase-jruby/table.rb', line 269 def put *args return put(args.first => args.last) if args.length == 2 puts = args.first.map { |rowkey, props| putify rowkey, props } htable.put puts puts.length end |
#remove_coprocessor!(name) ⇒ nil
Removes the coprocessor from the table.
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/hbase-jruby/table.rb', line 194 def remove_coprocessor! name unless org.apache.hadoop.hbase.HTableDescriptor.respond_to?(:removeCoprocessor) raise NotImplementedError, "org.apache.hadoop.hbase.HTableDescriptor.removeCoprocessor not implemented" end with_admin do |admin| while_disabled(admin) do htd = admin.get_table_descriptor(@name.to_java_bytes) htd.removeCoprocessor name admin.modifyTable @name.to_java_bytes, htd wait_async_admin(admin) end end end |
#truncate! ⇒ nil
Truncates the table by dropping it and recreating it.
233 234 235 236 237 |
# File 'lib/hbase-jruby/table.rb', line 233 def truncate! htd = htable.get_table_descriptor drop! create! htd end |