HBASE-15641 Shell "alter" should do a single modifyTable operation (Matt Warhaftig)
This commit is contained in:
parent
03f3c392a3
commit
ef47e1b68c
|
@ -585,6 +585,7 @@ module Hbase
|
||||||
|
|
||||||
# Get table descriptor
|
# Get table descriptor
|
||||||
htd = @admin.getTableDescriptor(table_name)
|
htd = @admin.getTableDescriptor(table_name)
|
||||||
|
hasTableUpdate = false
|
||||||
|
|
||||||
# Process all args
|
# Process all args
|
||||||
args.each do |arg|
|
args.each do |arg|
|
||||||
|
@ -605,18 +606,11 @@ module Hbase
|
||||||
|
|
||||||
# If column already exist, then try to alter it. Create otherwise.
|
# If column already exist, then try to alter it. Create otherwise.
|
||||||
if htd.hasFamily(column_name.to_java_bytes)
|
if htd.hasFamily(column_name.to_java_bytes)
|
||||||
@admin.modifyColumn(table_name, descriptor)
|
htd.modifyFamily(descriptor)
|
||||||
else
|
else
|
||||||
@admin.addColumn(table_name, descriptor)
|
htd.addFamily(descriptor)
|
||||||
end
|
end
|
||||||
|
hasTableUpdate = true
|
||||||
if wait == true
|
|
||||||
puts "Updating all regions with the new schema..."
|
|
||||||
alter_status(table_name_str)
|
|
||||||
end
|
|
||||||
|
|
||||||
# We bypass descriptor when adding column families; refresh it to apply other args correctly.
|
|
||||||
htd = @admin.getTableDescriptor(table_name)
|
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -626,7 +620,8 @@ module Hbase
|
||||||
# Delete column family
|
# Delete column family
|
||||||
if method == "delete"
|
if method == "delete"
|
||||||
raise(ArgumentError, "NAME parameter missing for delete method") unless name
|
raise(ArgumentError, "NAME parameter missing for delete method") unless name
|
||||||
@admin.deleteColumn(table_name, name.to_java_bytes)
|
htd.removeFamily(name.to_java_bytes)
|
||||||
|
hasTableUpdate = true
|
||||||
# Unset table attributes
|
# Unset table attributes
|
||||||
elsif method == "table_att_unset"
|
elsif method == "table_att_unset"
|
||||||
raise(ArgumentError, "NAME parameter missing for table_att_unset method") unless name
|
raise(ArgumentError, "NAME parameter missing for table_att_unset method") unless name
|
||||||
|
@ -643,7 +638,7 @@ module Hbase
|
||||||
end
|
end
|
||||||
htd.remove(name)
|
htd.remove(name)
|
||||||
end
|
end
|
||||||
@admin.modifyTable(table_name, htd)
|
hasTableUpdate = true
|
||||||
# Unknown method
|
# Unknown method
|
||||||
else
|
else
|
||||||
raise ArgumentError, "Unknown method: #{method}"
|
raise ArgumentError, "Unknown method: #{method}"
|
||||||
|
@ -653,15 +648,6 @@ module Hbase
|
||||||
puts("Unknown argument ignored: %s" % [unknown_key])
|
puts("Unknown argument ignored: %s" % [unknown_key])
|
||||||
end
|
end
|
||||||
|
|
||||||
if wait == true
|
|
||||||
puts "Updating all regions with the new schema..."
|
|
||||||
alter_status(table_name_str)
|
|
||||||
end
|
|
||||||
|
|
||||||
if method == "delete"
|
|
||||||
# We bypass descriptor when deleting column families; refresh it to apply other args correctly.
|
|
||||||
htd = @admin.getTableDescriptor(table_name)
|
|
||||||
end
|
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -706,18 +692,24 @@ module Hbase
|
||||||
arg.delete(key)
|
arg.delete(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
@admin.modifyTable(table_name, htd)
|
hasTableUpdate = true
|
||||||
|
|
||||||
arg.each_key do |unknown_key|
|
arg.each_key do |unknown_key|
|
||||||
puts("Unknown argument ignored: %s" % [unknown_key])
|
puts("Unknown argument ignored: %s" % [unknown_key])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Bulk apply all table modifications.
|
||||||
|
if hasTableUpdate
|
||||||
|
@admin.modifyTable(table_name, htd)
|
||||||
|
|
||||||
if wait == true
|
if wait == true
|
||||||
puts "Updating all regions with the new schema..."
|
puts "Updating all regions with the new schema..."
|
||||||
alter_status(table_name_str)
|
alter_status(table_name_str)
|
||||||
end
|
end
|
||||||
next
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
require 'shell'
|
require 'shell'
|
||||||
require 'shell/formatter'
|
require 'shell/formatter'
|
||||||
|
require 'stringio'
|
||||||
require 'hbase'
|
require 'hbase'
|
||||||
require 'hbase/hbase'
|
require 'hbase/hbase'
|
||||||
require 'hbase/table'
|
require 'hbase/table'
|
||||||
|
@ -295,12 +296,26 @@ module Hbase
|
||||||
|
|
||||||
define_test "alter should support more than one alteration in one call" do
|
define_test "alter should support more than one alteration in one call" do
|
||||||
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
|
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
|
||||||
admin.alter(@test_name, true, { NAME => 'z' }, { METHOD => 'delete', NAME => 'y' }, 'MAX_FILESIZE' => 12345678)
|
alterOutput = capture_stdout { admin.alter(@test_name, true, { NAME => 'z' },
|
||||||
|
{ METHOD => 'delete', NAME => 'y' }, 'MAX_FILESIZE' => 12345678) }
|
||||||
admin.enable(@test_name)
|
admin.enable(@test_name)
|
||||||
|
assert_equal(1, /Updating all regions/.match(alterOutput).size,
|
||||||
|
"HBASE-15641 - Should only perform one table modification per alter.")
|
||||||
assert_equal(['x:', 'z:'], table(@test_name).get_all_columns.sort)
|
assert_equal(['x:', 'z:'], table(@test_name).get_all_columns.sort)
|
||||||
assert_match(/12345678/, admin.describe(@test_name))
|
assert_match(/12345678/, admin.describe(@test_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def capture_stdout
|
||||||
|
begin
|
||||||
|
old_stdout = $stdout
|
||||||
|
$stdout = StringIO.new('','w')
|
||||||
|
yield
|
||||||
|
$stdout.string
|
||||||
|
ensure
|
||||||
|
$stdout = old_stdout
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
define_test 'alter should support shortcut DELETE alter specs' do
|
define_test 'alter should support shortcut DELETE alter specs' do
|
||||||
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
|
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
|
||||||
admin.alter(@test_name, true, 'delete' => 'y')
|
admin.alter(@test_name, true, 'delete' => 'y')
|
||||||
|
|
Loading…
Reference in New Issue