in linkis-engineconn-plugins/hbase/hbase-shims-2.2.6/src/main/resources/hbase-ruby/hbase/admin.rb [671:808]
def alter(table_name_str, wait = true, *args)
raise(ArgumentError, 'Table name must be of type String') unless
table_name_str.is_a?(String)
raise(ArgumentError, "Can't find a table: #{table_name_str}") unless exists?(table_name_str)
raise(ArgumentError, 'There should be at least one argument but the table name') if args.empty?
table_name = TableName.valueOf(table_name_str)
htd = org.apache.hadoop.hbase.HTableDescriptor.new(@admin.getTableDescriptor(table_name))
hasTableUpdate = false
args.each do |arg|
arg = { NAME => arg } if arg.is_a?(String)
arg = { METHOD => 'delete', NAME => arg['delete'] } if arg['delete']
method = arg.delete(METHOD)
if method.nil? && arg.key?(NAME)
descriptor = hcd(arg, htd)
column_name = descriptor.getNameAsString
if htd.hasFamily(column_name.to_java_bytes)
htd.modifyFamily(descriptor)
else
htd.addFamily(descriptor)
end
hasTableUpdate = true
next
end
name = arg.delete(NAME)
if !method.nil? && method != 'table_att'
if method == 'delete'
raise(ArgumentError, 'NAME parameter missing for delete method') unless name
htd.removeFamily(name.to_java_bytes)
hasTableUpdate = true
elsif method == 'table_att_unset'
raise(ArgumentError, 'NAME parameter missing for table_att_unset method') unless name
if name.is_a?(Array)
name.each do |key|
if htd.getValue(key).nil?
raise ArgumentError, "Could not find attribute: #{key}"
end
htd.remove(key)
end
else
if htd.getValue(name).nil?
raise ArgumentError, "Could not find attribute: #{name}"
end
htd.remove(name)
end
hasTableUpdate = true
elsif method == 'table_conf_unset'
raise(ArgumentError, 'NAME parameter missing for table_conf_unset method') unless name
if name.is_a?(Array)
name.each do |key|
if htd.getConfigurationValue(key).nil?
raise ArgumentError, "Could not find configuration: #{key}"
end
htd.removeConfiguration(key)
end
else
if htd.getConfigurationValue(name).nil?
raise ArgumentError, "Could not find configuration: #{name}"
end
htd.removeConfiguration(name)
end
hasTableUpdate = true
else
raise ArgumentError, "Unknown method: #{method}"
end
arg.each_key do |unknown_key|
puts(format('Unknown argument ignored: %s', unknown_key))
end
next
end
update_htd_from_arg(htd, arg)
valid_coproc_keys = []
next unless arg.is_a?(Hash)
arg.each do |key, value|
k = String.new(key)
k.strip!
next unless k =~ /coprocessor/i
v = String.new(value)
v.strip!
htd.addCoprocessorWithSpec(v)
valid_coproc_keys << key
end
valid_coproc_keys.each do |key|
arg.delete(key)
end
hasTableUpdate = true
arg.each_key do |unknown_key|
puts(format('Unknown argument ignored: %s', unknown_key))
end
next
end
if hasTableUpdate
@admin.modifyTable(table_name, htd)
if wait == true
puts 'Updating all regions with the new schema...'
alter_status(table_name_str)
end
end
end