From e8ea2c8c460550a0750a2e1aee548da7b88c165e Mon Sep 17 00:00:00 2001 From: Ashish Singhi Date: Fri, 27 Feb 2015 15:56:48 +0530 Subject: [PATCH] HBASE-13100 Shell command to retrieve table splits --- hbase-shell/src/main/ruby/hbase/table.rb | 11 +++++ hbase-shell/src/main/ruby/shell.rb | 1 + .../src/main/ruby/shell/commands/get_splits.rb | 47 ++++++++++++++++++++++ hbase-shell/src/test/ruby/hbase/table_test.rb | 6 +++ 4 files changed, 65 insertions(+) create mode 100644 hbase-shell/src/main/ruby/shell/commands/get_splits.rb diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index eaa2d5c..d4ed5a4 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -678,5 +678,16 @@ EOF column[1] = parts[0] end end + + #---------------------------------------------------------------------------------------------- + # Get the split points for the table + def _get_splits_internal() + locator = @table.getRegionLocator() + 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..16296fd 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -301,6 +301,7 @@ Shell.load_command_group( truncate truncate_preserve append + get_splits ] ) 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..0e1243d --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/get_splits.rb @@ -0,0 +1,47 @@ +# +# +# 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 diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb index dc4dc0d..5374f43 100644 --- a/hbase-shell/src/test/ruby/hbase/table_test.rb +++ b/hbase-shell/src/test/ruby/hbase/table_test.rb @@ -611,5 +611,11 @@ module Hbase end end + define_test "Split count should be one" do + splits = @test_table._get_splits_internal() + assert_equal(1, splits.size) + assert_equal([""], splits) + end + end end -- 1.9.2.msysgit.0