diff --git hbase-server/src/main/ruby/hbase.rb hbase-server/src/main/ruby/hbase.rb index 889d695..17eb923 100644 --- hbase-server/src/main/ruby/hbase.rb +++ hbase-server/src/main/ruby/hbase.rb @@ -56,6 +56,7 @@ module HBaseConstants SPLITS_FILE = 'SPLITS_FILE' SPLITALGO = 'SPLITALGO' NUMREGIONS = 'NUMREGIONS' + TABLE_CONFIG = 'TABLE_CONFIG' # Load constants from hbase java API def self.promote_constants(constants) diff --git hbase-server/src/main/ruby/hbase/admin.rb hbase-server/src/main/ruby/hbase/admin.rb index 9f86932..b5f29d5 100644 --- hbase-server/src/main/ruby/hbase/admin.rb +++ hbase-server/src/main/ruby/hbase/admin.rb @@ -203,7 +203,7 @@ module Hbase # the arg is a string, default action is to add a column to the table htd.addFamily(hcd(arg, htd)) else - # arg is a hash. 4 possibilities: + # arg is a hash. 5 possibilities: if (arg.has_key?(SPLITS) or arg.has_key?(SPLITS_FILE)) if arg.has_key?(SPLITS_FILE) unless File.exist?(arg[SPLITS_FILE]) @@ -246,12 +246,12 @@ module Hbase splits = split_algo.split(JInteger.valueOf(num_regions)) end if arg[CONFIG] - raise(ArgumentError, "#{CONFIG} must be a Hash type") unless arg.kind_of?(Hash) - for k,v in arg[CONFIG] - v = v.to_s unless v.nil? - htd.setValue(k, v) - end + apply_config(htd, arg[CONFIG]) end + elsif (cfg = arg.delete(TABLE_CONFIG)) + # We just want to set the config. We have to use a different name from CONFIG because that + # will conflict with column family spec below. + apply_config(htd, cfg) else # (3) column family spec descriptor = hcd(arg, htd) @@ -378,10 +378,15 @@ module Hbase # Note that we handle owner here, and also below (see (2)) as part of the "METHOD => 'table_att'" table attributes. # In other words, if OWNER is specified, then METHOD is set to table_att. # alter 'tablename', {OWNER => 'username'} (that is, METHOD => 'table_att' is not specified). + # Similarly with CONFIG. As in create, we'll use a different name to not conflict with CONFIG in column spec. if arg[OWNER] htd.setOwnerString(arg[OWNER]) @admin.modifyTable(table_name.to_java_bytes, htd) return + elsif arg[TABLE_CONFIG] + apply_config(htd, arg[TABLE_CONFIG]) + @admin.modifyTable(table_name.to_java_bytes, htd) + return end descriptor = hcd(arg, htd) @@ -459,11 +464,7 @@ module Hbase end if arg[CONFIG] - raise(ArgumentError, "#{CONFIG} must be a Hash type") unless arg.kind_of?(Hash) - for k,v in arg[CONFIG] - v = v.to_s unless v.nil? - htd.setValue(k, v) - end + apply_config(htd, arg[CONFIG]) end @admin.modifyTable(table_name.to_java_bytes, htd) if wait == true @@ -554,7 +555,7 @@ module Hbase def exists?(table_name) @admin.tableExists(table_name) end - + #---------------------------------------------------------------------------------------------- # Is table enabled def enabled?(table_name) @@ -607,11 +608,7 @@ module Hbase end if arg[CONFIG] - raise(ArgumentError, "#{CONFIG} must be a Hash type") unless arg.kind_of?(Hash) - for k,v in arg[CONFIG] - v = v.to_s unless v.nil? - family.setValue(k, v) - end + apply_config(family, arg[CONFIG]) end return family end @@ -638,5 +635,15 @@ module Hbase put.add(org.apache.hadoop.hbase.HConstants::CATALOG_FAMILY, org.apache.hadoop.hbase.HConstants::REGIONINFO_QUALIFIER, org.apache.hadoop.hbase.util.Writables.getBytes(hri)) meta.put(put) end + + # Apply config to table/column descriptor + def apply_config(descriptor, config) + raise(ArgumentError, "#{CONFIG} must be a Hash type") unless config.kind_of?(Hash) + for k,v in config + v = v.to_s unless v.nil? + descriptor.setValue(k, v) + end + end + end end