From 9dc0e78e7718a0546da59646c72b44bd5edacabc Mon Sep 17 00:00:00 2001 From: Nick Dimiduk Date: Wed, 24 Apr 2013 08:23:04 -0700 Subject: [PATCH] HBASE-8378 [shell] add 'force' option to drop New optional argument to 'drop' shell command will disable a table on user's behalf when necessary. hbase(main):001:0> create 't1', 'f1' 0 row(s) in 0.9640 seconds => Hbase::Table - t1 hbase(main):002:0> drop 't1' ERROR: Table t1 is enabled. Disable it first.' Here is some help for this command: Drop the named table. Table must first be disabled unless the second, optional argument 'force' is specified as true. e.g. hbase> drop 't1' hbase> drop 't1', true hbase(main):003:0> disable 't1' 0 row(s) in 2.0700 seconds hbase(main):004:0> drop 't1' 0 row(s) in 6.1020 seconds hbase(main):005:0> create 't1', 'f1' 0 row(s) in 1.0750 seconds => Hbase::Table - t1 hbase(main):006:0> drop 't1', true 0 row(s) in 3.1180 seconds --- hbase-server/src/main/ruby/hbase/admin.rb | 11 ++++++++--- hbase-server/src/main/ruby/shell/commands/drop.rb | 10 +++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/ruby/hbase/admin.rb b/hbase-server/src/main/ruby/hbase/admin.rb index c10e7b7..73ed9b9 100644 --- a/hbase-server/src/main/ruby/hbase/admin.rb +++ b/hbase-server/src/main/ruby/hbase/admin.rb @@ -168,9 +168,14 @@ module Hbase #---------------------------------------------------------------------------------------------- # Drops a table - def drop(table_name) - tableExists(table_name) - raise ArgumentError, "Table #{table_name} is enabled. Disable it first.'" if enabled?(table_name) + def drop(table_name, force = false) + if (force) + return unless exists?(table_name) + disable(table_name) + else + tableExists(table_name) + raise ArgumentError, "Table #{table_name} is enabled. Disable it first.'" if enabled?(table_name) + end @admin.deleteTable(table_name) end diff --git a/hbase-server/src/main/ruby/shell/commands/drop.rb b/hbase-server/src/main/ruby/shell/commands/drop.rb index 6238fe6..660d69d 100644 --- a/hbase-server/src/main/ruby/shell/commands/drop.rb +++ b/hbase-server/src/main/ruby/shell/commands/drop.rb @@ -22,13 +22,17 @@ module Shell class Drop < Command def help return <<-EOF -Drop the named table. Table must first be disabled: e.g. "hbase> drop 't1'" +Drop the named table. Table must first be disabled unless the second, optional +argument 'force' is specified as true. e.g. + +hbase> drop 't1' +hbase> drop 't1', true EOF end - def command(table) + def command(table, force = false) format_simple_command do - admin.drop(table) + admin.drop(table, force) end end end -- 1.8.1