hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject hbase git commit: HBASE-13100 Shell command to retrieve table splits
Date Tue, 03 Mar 2015 05:46:46 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 6e6cf74c1 -> 5e993eeef


HBASE-13100 Shell command to retrieve table splits


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/5e993eee
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/5e993eee
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/5e993eee

Branch: refs/heads/0.98
Commit: 5e993eeefdf96579e7aed8d03d215e7df2e52d0d
Parents: 6e6cf74
Author: Ashish Singhi <ashish.singhi@huawei.com>
Authored: Tue Mar 3 10:52:41 2015 +0530
Committer: Sean Busbey <busbey@apache.org>
Committed: Mon Mar 2 23:41:08 2015 -0600

----------------------------------------------------------------------
 hbase-shell/src/main/ruby/hbase/table.rb        |  9 ++++
 hbase-shell/src/main/ruby/shell.rb              |  1 +
 .../src/main/ruby/shell/commands/get_splits.rb  | 46 ++++++++++++++++++++
 hbase-shell/src/test/ruby/hbase/table_test.rb   | 17 ++++++++
 hbase-shell/src/test/ruby/test_helper.rb        | 12 +++++
 5 files changed, 85 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/5e993eee/hbase-shell/src/main/ruby/hbase/table.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb
index 10b754a..b1d2671 100644
--- a/hbase-shell/src/main/ruby/hbase/table.rb
+++ b/hbase-shell/src/main/ruby/hbase/table.rb
@@ -669,5 +669,14 @@ EOF
         column[1] = parts[0]
       end
     end
+
+    #----------------------------------------------------------------------------------------------
+    # Get the split points for the table
+    def _get_splits_internal()
+      splits = @table.getRegionLocations().keys().
+          map{|i| Bytes.toStringBinary(i.getStartKey)}.delete_if{|k| k == ""}
+      puts("Total number of splits = %s" % [splits.size + 1])
+      return splits
+    end
   end
 end

http://git-wip-us.apache.org/repos/asf/hbase/blob/5e993eee/hbase-shell/src/main/ruby/shell.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb
index d934846..6af4473 100644
--- a/hbase-shell/src/main/ruby/shell.rb
+++ b/hbase-shell/src/main/ruby/shell.rb
@@ -294,6 +294,7 @@ Shell.load_command_group(
     truncate
     truncate_preserve
     append
+    get_splits
   ]
 )
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/5e993eee/hbase-shell/src/main/ruby/shell/commands/get_splits.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/get_splits.rb b/hbase-shell/src/main/ruby/shell/commands/get_splits.rb
new file mode 100644
index 0000000..8b6ae82
--- /dev/null
+++ b/hbase-shell/src/main/ruby/shell/commands/get_splits.rb
@@ -0,0 +1,46 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+module Shell
+  module Commands
+    class GetSplits < Command
+      def help
+        return <<-EOF
+Get the splits of the named table:
+  hbase> get_splits 't1'
+  hbase> get_splits 'ns1:t1'
+
+The same commands also can be run on a table reference. Suppose you had a reference
+t to table 't1', the corresponding command would be:
+
+  hbase> t.get_splits
+EOF
+      end
+
+      def command(table)
+        get_splits(table(table))
+      end
+
+      def get_splits(table)
+        table._get_splits_internal()
+      end
+    end
+  end
+end
+
+::Hbase::Table.add_shell_command("get_splits")
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hbase/blob/5e993eee/hbase-shell/src/test/ruby/hbase/table_test.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb
index d634992..86780a1 100644
--- a/hbase-shell/src/test/ruby/hbase/table_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/table_test.rb
@@ -573,5 +573,22 @@ module Hbase
       end
     end
 
+    define_test "Split count for a table" do
+      @testTableName = "tableWithSplits"
+      create_test_table_with_splits(@testTableName, SPLITS => ['10', '20', '30', '40'])
+      @table = table(@testTableName)
+      splits = @table._get_splits_internal()
+      #Total splits is 5 but here count is 4 as we ignore implicit empty split.
+      assert_equal(4, splits.size)
+      assert_equal(["10", "20", "30", "40"], splits)
+      drop_test_table(@testTableName)
+    end
+
+    define_test "Split count for a empty table" do
+      splits = @test_table._get_splits_internal()
+      #Empty split should not be part of this array.
+      assert_equal(0, splits.size)
+      assert_equal([], splits)
+    end
   end
 end

http://git-wip-us.apache.org/repos/asf/hbase/blob/5e993eee/hbase-shell/src/test/ruby/test_helper.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/test_helper.rb b/hbase-shell/src/test/ruby/test_helper.rb
index a776c23..4ab56f2 100644
--- a/hbase-shell/src/test/ruby/test_helper.rb
+++ b/hbase-shell/src/test/ruby/test_helper.rb
@@ -77,6 +77,18 @@ module Hbase
       end
     end
 
+    def create_test_table_with_splits(name, splits)
+      # Create the table if needed
+      unless admin.exists?(name)
+        admin.create name, 'f1', splits
+      end
+
+      # Enable the table if needed
+      unless admin.enabled?(name)
+        admin.enable(name)
+      end
+    end
+
     def drop_test_table(name)
       return unless admin.exists?(name)
       begin


Mime
View raw message