HBASE-13100 Shell command to retrieve table splits

This commit is contained in:
Ashish Singhi 2015-02-28 17:45:58 +05:30 committed by Sean Busbey
parent fdb48a7bbe
commit c80d64c3fe
5 changed files with 87 additions and 0 deletions

View File

@ -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)}.delete_if{|k| k == ""}
locator.close()
puts("Total number of splits = %s" % [splits.size + 1])
return splits
end
end
end

View File

@ -301,6 +301,7 @@ Shell.load_command_group(
truncate
truncate_preserve
append
get_splits
]
)

View File

@ -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")

View File

@ -611,5 +611,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

View File

@ -85,6 +85,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