From baa15ba327173f8436208f3515921ba6d83bf6d1 Mon Sep 17 00:00:00 2001 From: Ashish Singhi Date: Fri, 27 Feb 2015 12:22:17 +0530 Subject: [PATCH] HBASE-13100 Shell command to retrieve table splits --- hbase-shell/src/main/ruby/hbase/admin.rb | 10 +++++++ hbase-shell/src/main/ruby/shell.rb | 1 + .../src/main/ruby/shell/commands/get_splits.rb | 35 ++++++++++++++++++++++ hbase-shell/src/test/ruby/hbase/admin_test.rb | 9 ++++++ 4 files changed, 55 insertions(+) create mode 100644 hbase-shell/src/main/ruby/shell/commands/get_splits.rb diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index 12571d9..5e6fbb4 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -976,5 +976,15 @@ module Hbase @admin.deleteNamespace(namespace_name) end + # Get the splits of the named table + def get_splits(table_name) + tableExists(table_name) + locator = @connection.getRegionLocator(TableName.valueOf(table_name)) + splits = locator.getAllRegionLocations(). + map{|i| Bytes.toStringBinary(i.getRegionInfo().getStartKey)} + locator.close() + puts("Total number of splits = %s" % [splits.size]) + return splits + end end end diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index 893079d..057f4d3 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -267,6 +267,7 @@ Shell.load_command_group( alter_status alter_async get_table + get_splits ], :aliases => { 'describe' => ['desc'] 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..1722c7e --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/get_splits.rb @@ -0,0 +1,35 @@ +# +# +# 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' +EOF + end + def command(table) + admin.get_splits(table) + end + end + end +end diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test.rb index 1925864..1b611fd 100644 --- a/hbase-shell/src/test/ruby/hbase/admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb @@ -368,5 +368,14 @@ module Hbase define_test "Get replication sink metrics information" do replication_status("replication", "sink") end + + define_test "Get the splits of the named table" do + admin.create('testGetSplits', 'f1', SPLITS => ['10', '20', '30', '40']) + splits = admin.get_splits('testGetSplits') + assert_equal(5, splits.size) + assert_equal(["", "10", "20", "30", "40"], splits) + drop_test_table('testGetSplits') + end + end end -- 1.9.2.msysgit.0