From cec1add3fa0cf89c790ce2606b858bf12ad1d26c Mon Sep 17 00:00:00 2001 From: Pawan Kondavaty Date: Fri, 25 Jan 2019 16:56:28 -0500 Subject: [PATCH 1/3] Update the dependencies --- lib/hbase-jruby/cell.rb | 4 ++-- lib/hbase-jruby/dependency.rb | 4 +++- lib/hbase-jruby/hbase.rb | 19 +++++-------------- lib/hbase-jruby/row.rb | 4 ++-- lib/hbase-jruby/schema.rb | 2 +- lib/hbase-jruby/scoped.rb | 6 +++--- lib/hbase-jruby/table.rb | 2 +- lib/hbase-jruby/table/admin.rb | 6 +++--- lib/hbase-jruby/table/mutation.rb | 16 ++++++++-------- lib/hbase-jruby/util.rb | 6 +++--- lib/hbase-jruby/version.rb | 2 +- 11 files changed, 32 insertions(+), 39 deletions(-) diff --git a/lib/hbase-jruby/cell.rb b/lib/hbase-jruby/cell.rb index 821421a..36b6b05 100644 --- a/lib/hbase-jruby/cell.rb +++ b/lib/hbase-jruby/cell.rb @@ -33,7 +33,7 @@ def family # Can be one of :string, :symbol, :fixnum, :float, :short, :int, :bigdecimal, :boolean and :raw. # @return [Object] def qualifier type = :string - Util.from_bytes type, @java.getQualifier + Util.from_bytes type, @java.getQualifierArray end alias cq qualifier @@ -53,7 +53,7 @@ def value # Returns the value of the cell as a Java byte array # @return [byte[]] def raw - @java.getValue + @java.getValueArray end # Returns the column value as a String diff --git a/lib/hbase-jruby/dependency.rb b/lib/hbase-jruby/dependency.rb index eee0edb..06cd51f 100644 --- a/lib/hbase-jruby/dependency.rb +++ b/lib/hbase-jruby/dependency.rb @@ -11,10 +11,11 @@ class HBase # @private @deps = { self => %w[ + org.apache.hadoop.hbase.client.ConnectionFactory org.apache.hadoop.hbase.HBaseConfiguration org.apache.hadoop.hbase.client.HBaseAdmin - org.apache.hadoop.hbase.client.HConnectionManager org.apache.hadoop.hbase.client.HTablePool + org.apache.hadoop.hbase.TableName ], Util => %w[ java.nio.ByteBuffer @@ -27,6 +28,7 @@ class HBase ], Cell => %w[ org.apache.hadoop.hbase.KeyValue + org.apache.hadoop.hbase.CellUtil ], Result => %w[ org.apache.hadoop.hbase.util.Bytes diff --git a/lib/hbase-jruby/hbase.rb b/lib/hbase-jruby/hbase.rb index aeed518..e282b83 100644 --- a/lib/hbase-jruby/hbase.rb +++ b/lib/hbase-jruby/hbase.rb @@ -13,7 +13,7 @@ class HBase include Admin include HBase::Util - DEFAULT_COLUMN_CACHE_SIZE = 200 + DEFAULT_COLUMN_CACHE_SIZE ||= 200 # @overload HBase.log4j=(filename) # Configure Log4j logging with the given file @@ -33,13 +33,13 @@ def self.log4j= arg arg.each do |k, v| props.setProperty k.to_s, v.to_s end - org.apache.log4j.PropertyConfigurator.configure props + # org.apache.log4j.PropertyConfigurator.configure props else case File.extname(arg).downcase when '.xml' org.apache.log4j.xml.DOMConfigurator.configure arg else - org.apache.log4j.PropertyConfigurator.configure arg + # org.apache.log4j.PropertyConfigurator.configure arg end end end @@ -74,7 +74,7 @@ def initialize config = {} end end end - @connection = HConnectionManager.createConnection @config + @connection = ConnectionFactory.createConnection @config @htable_pool = if @connection.respond_to?(:getTable) nil @@ -112,16 +112,7 @@ def close @mutex.synchronize do unless @closed @closed = true - @htable_pool.close if use_table_pool? @connection.close - - # To be deprecated - begin - HConnectionManager.deleteConnection(@config) - rescue ArgumentError - # HBase 0.92 or below - HConnectionManager.deleteConnection(@config, true) - end if use_table_pool? end end @@ -214,7 +205,7 @@ def reset_table_pool private def get_htable name - (@htable_pool || @connection).get_table name + (@htable_pool || @connection).get_table TableName.valueOf name end def check_closed diff --git a/lib/hbase-jruby/row.rb b/lib/hbase-jruby/row.rb index 0afe67b..1348241 100644 --- a/lib/hbase-jruby/row.rb +++ b/lib/hbase-jruby/row.rb @@ -23,7 +23,7 @@ def rowkey type = :raw # Enumerates through cells def each return enum_for(:each) unless block_given? - @result.raw.each do |kv| + @result.rawCells.each do |kv| yield Cell.new(@table, kv) end end @@ -317,5 +317,5 @@ def allmap end#HBase # For backward compatibility -HBase::Result = HBase::Row +HBase::Result ||= HBase::Row diff --git a/lib/hbase-jruby/schema.rb b/lib/hbase-jruby/schema.rb index e257b12..03725a6 100644 --- a/lib/hbase-jruby/schema.rb +++ b/lib/hbase-jruby/schema.rb @@ -123,7 +123,7 @@ def empty_lookup_table } end - KNOWN_TYPES = Set[ + KNOWN_TYPES ||= Set[ :string, :str, :symbol, :sym, :byte, :boolean, :bool, diff --git a/lib/hbase-jruby/scoped.rb b/lib/hbase-jruby/scoped.rb index 8a13384..fad0d23 100644 --- a/lib/hbase-jruby/scoped.rb +++ b/lib/hbase-jruby/scoped.rb @@ -397,7 +397,7 @@ def getify rowkey case @trange when Array get.setTimeRange(*@trange) - when Time, Fixnum + when Time, Integer get.setTimeStamp @trange end @@ -495,7 +495,7 @@ def filter_for cf, cq, type, val def set_max_versions obj case @versions - when Fixnum + when Integer obj.setMaxVersions @versions when :all obj.setMaxVersions @@ -547,7 +547,7 @@ def filtered_scan case @trange when Array scan.setTimeRange(*@trange) - when Time, Fixnum + when Time, Integer scan.setTimeStamp @trange end diff --git a/lib/hbase-jruby/table.rb b/lib/hbase-jruby/table.rb index 597e9ef..b2d85b8 100644 --- a/lib/hbase-jruby/table.rb +++ b/lib/hbase-jruby/table.rb @@ -352,7 +352,7 @@ def check_closed raise RuntimeError, "HBase connection is already closed" if @hbase.closed? end - INSENSITIVE_ROW_HASH = {}.tap { |h| + INSENSITIVE_ROW_HASH ||= {}.tap { |h| h.instance_eval do def [] key if Util.java_bytes?(key) diff --git a/lib/hbase-jruby/table/admin.rb b/lib/hbase-jruby/table/admin.rb index 2d62544..1bd7b3c 100644 --- a/lib/hbase-jruby/table/admin.rb +++ b/lib/hbase-jruby/table/admin.rb @@ -261,7 +261,7 @@ def snapshots end private - COLUMN_PROPERTIES = { + COLUMN_PROPERTIES ||= { :blockcache => { :set => :setBlockCacheEnabled, :get => :isBlockCacheEnabled }, :blocksize => { :set => :setBlocksize, :get => :getBlocksize }, :bloomfilter => { :set => :setBloomFilterType, :get => :getBloomFilterType }, @@ -281,7 +281,7 @@ def snapshots :versions => { :set => :setMaxVersions, :get => :getMaxVersions }, } - TABLE_PROPERTIES = { + TABLE_PROPERTIES ||= { :max_filesize => { :get => :getMaxFileSize, :set => :setMaxFileSize }, :readonly => { :get => :isReadOnly, :set => :setReadOnly }, :memstore_flushsize => { :get => :getMemStoreFlushSize, :set => :setMemStoreFlushSize }, @@ -311,7 +311,7 @@ def snapshots } } - MAX_SPLIT_WAIT = 30 + MAX_SPLIT_WAIT ||= 30 def hcd obj, opts hcd = diff --git a/lib/hbase-jruby/table/mutation.rb b/lib/hbase-jruby/table/mutation.rb index 588bd6a..38504a7 100644 --- a/lib/hbase-jruby/table/mutation.rb +++ b/lib/hbase-jruby/table/mutation.rb @@ -20,24 +20,24 @@ def put rowkey, props, timestamp = nil val.each do |t, v| case t # Timestamp / Ruby Time - when Time, Fixnum - put.add cf, cq, time_to_long(t), Util.to_typed_bytes(type, v) + when Time, Integer + put.addColumn cf.to_java_bytes, cq.to_java_bytes, time_to_long(t), Util.to_typed_bytes(type, v) # Types: :byte, :short, :int, ... else - put.add cf, cq, Util.to_typed_bytes(t, v) + put.addColumn cf.to_java_bytes, cq.to_java_bytes, Util.to_typed_bytes(t, v) end unless v.nil? end when String if timestamp - put.add cf, cq, time_to_long(timestamp), val.to_java_bytes + put.addColumn cf.to_java_bytes, cq.to_java_bytes, time_to_long(timestamp), val.to_java_bytes else - put.add cf, cq, val.to_java_bytes + put.addColumn cf.to_java_bytes, cq.to_java_bytes, val.to_java_bytes end else if timestamp - put.add cf, cq, time_to_long(timestamp), Util.to_typed_bytes(type, val) + put.addColumn cf.to_java_bytes, cq.to_java_bytes, time_to_long(timestamp), Util.to_typed_bytes(type, val) else - put.add cf, cq, Util.to_typed_bytes(type, val) + put.addColumn cf.to_java_bytes, cq.to_java_bytes, Util.to_typed_bytes(type, val) end end end @@ -63,7 +63,7 @@ def delete rowkey, *extra extra.each do |x| case x - when Fixnum, Time + when Integer, Time if cq del.deleteColumn cf, cq, time_to_long(x) prcd = true diff --git a/lib/hbase-jruby/util.rb b/lib/hbase-jruby/util.rb index b83727d..6883894 100644 --- a/lib/hbase-jruby/util.rb +++ b/lib/hbase-jruby/util.rb @@ -2,8 +2,8 @@ class HBase module Util - JAVA_BYTE_ARRAY_EMPTY = [].to_java(Java::byte) - JAVA_BYTE_ARRAY_CLASS = JAVA_BYTE_ARRAY_EMPTY.java_class + JAVA_BYTE_ARRAY_EMPTY ||= [].to_java(Java::byte) + JAVA_BYTE_ARRAY_CLASS ||= JAVA_BYTE_ARRAY_EMPTY.java_class class << self def java_bytes? v @@ -167,7 +167,7 @@ def parse_column_name col raise ArgumentError, "Column family not specified" else col = col.to_s - cfcq = KeyValue.parseColumn(col.to_java_bytes) + cfcq = col.split(':') #KeyValue.parseColumn(col.to_java_bytes) cf = cfcq[0] cq = if cfcq.length == 2 cfcq[1] diff --git a/lib/hbase-jruby/version.rb b/lib/hbase-jruby/version.rb index f77c680..b463aeb 100644 --- a/lib/hbase-jruby/version.rb +++ b/lib/hbase-jruby/version.rb @@ -1,5 +1,5 @@ class HBase module JRuby - VERSION = '0.7.1' + VERSION ||= '0.7.1' end end From fa15dc5d669cd55cc5abd84257baaeb3ae8277f1 Mon Sep 17 00:00:00 2001 From: Pawan Kondavaty Date: Tue, 29 Jan 2019 16:57:07 -0500 Subject: [PATCH 2/3] Update to convert the Column family and qualifier into bytes --- lib/hbase-jruby/util.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hbase-jruby/util.rb b/lib/hbase-jruby/util.rb index 6883894..d2edaa2 100644 --- a/lib/hbase-jruby/util.rb +++ b/lib/hbase-jruby/util.rb @@ -21,7 +21,7 @@ def to_bytes v v.to_java(Java::byte) when String, ByteArray v.to_java_bytes - when Fixnum + when Integer Bytes.java_send :toBytes, [Java::long], v when Symbol v.to_s.to_java_bytes @@ -174,7 +174,7 @@ def parse_column_name col elsif col[-1, 1] == ':' JAVA_BYTE_ARRAY_EMPTY end - return cf, cq + return to_bytes(cf), to_bytes(cq) end end end From 784efc9328bdb82e19fe0b356f2cdb164883ea67 Mon Sep 17 00:00:00 2001 From: Pawan Kondavaty Date: Wed, 30 Jan 2019 10:31:00 -0500 Subject: [PATCH 3/3] Update parse column method --- lib/hbase-jruby/table/mutation.rb | 12 ++++++------ lib/hbase-jruby/util.rb | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/hbase-jruby/table/mutation.rb b/lib/hbase-jruby/table/mutation.rb index 38504a7..9176c5e 100644 --- a/lib/hbase-jruby/table/mutation.rb +++ b/lib/hbase-jruby/table/mutation.rb @@ -21,23 +21,23 @@ def put rowkey, props, timestamp = nil case t # Timestamp / Ruby Time when Time, Integer - put.addColumn cf.to_java_bytes, cq.to_java_bytes, time_to_long(t), Util.to_typed_bytes(type, v) + put.addColumn cf, cq, time_to_long(t), Util.to_typed_bytes(type, v) # Types: :byte, :short, :int, ... else - put.addColumn cf.to_java_bytes, cq.to_java_bytes, Util.to_typed_bytes(t, v) + put.addColumn cf, cq, Util.to_typed_bytes(t, v) end unless v.nil? end when String if timestamp - put.addColumn cf.to_java_bytes, cq.to_java_bytes, time_to_long(timestamp), val.to_java_bytes + put.addColumn cf, cq, time_to_long(timestamp), val.to_java_bytes else - put.addColumn cf.to_java_bytes, cq.to_java_bytes, val.to_java_bytes + put.addColumn cf, cq, val.to_java_bytes end else if timestamp - put.addColumn cf.to_java_bytes, cq.to_java_bytes, time_to_long(timestamp), Util.to_typed_bytes(type, val) + put.addColumn cf, cq, time_to_long(timestamp), Util.to_typed_bytes(type, val) else - put.addColumn cf.to_java_bytes, cq.to_java_bytes, Util.to_typed_bytes(type, val) + put.addColumn cf, cq, Util.to_typed_bytes(type, val) end end end diff --git a/lib/hbase-jruby/util.rb b/lib/hbase-jruby/util.rb index d2edaa2..2d61723 100644 --- a/lib/hbase-jruby/util.rb +++ b/lib/hbase-jruby/util.rb @@ -167,14 +167,14 @@ def parse_column_name col raise ArgumentError, "Column family not specified" else col = col.to_s - cfcq = col.split(':') #KeyValue.parseColumn(col.to_java_bytes) - cf = cfcq[0] + cfcq = col.split(':') + cf = cfcq[0].to_java_bytes cq = if cfcq.length == 2 - cfcq[1] + cfcq[1].to_java_bytes elsif col[-1, 1] == ':' JAVA_BYTE_ARRAY_EMPTY end - return to_bytes(cf), to_bytes(cq) + return cf, cq end end end