From 8a26426945279c256f3439f44eeb838c17b87977 Mon Sep 17 00:00:00 2001 From: Nick Dimiduk Date: Tue, 23 Apr 2013 15:09:29 -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):002:0> create 't1', 'f1' 0 row(s) in 0.3110 seconds => Hbase::Table - t1 hbase(main):003: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):004:0> drop 't1', true 0 row(s) in 13.1480 seconds hbase(main):005:0> list TABLE 0 row(s) in 0.0260 seconds => [] --- hbase-server/src/main/ruby/hbase/admin.rb | 7 ++++++- hbase-server/src/main/ruby/shell/commands/drop.rb | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hbase-server/src/main/ruby/hbase/admin.rb b/hbase-server/src/main/ruby/hbase/admin.rb index c10e7b7..6d6bb71 100644 --- a/hbase-server/src/main/ruby/hbase/admin.rb +++ b/hbase-server/src/main/ruby/hbase/admin.rb @@ -168,7 +168,12 @@ module Hbase #---------------------------------------------------------------------------------------------- # Drops a table - def drop(table_name) + def drop(table_name, force = false) + if (force) + return unless exists?(table_name) + disable(table_name) + end + tableExists(table_name) raise ArgumentError, "Table #{table_name} is enabled. Disable it first.'" if enabled?(table_name) 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