HBASE-4000 You can't specify split points when you create a table in the shell

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1137257 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-06-18 22:12:07 +00:00
parent 1573c985d5
commit a3d1ab8df0
4 changed files with 39 additions and 9 deletions

View File

@ -128,6 +128,8 @@ Release 0.91.0 - Unreleased
HBASE-3793 HBASE-3468 Broke checkAndPut with null value (Ming Ma) HBASE-3793 HBASE-3468 Broke checkAndPut with null value (Ming Ma)
HBASE-3995 HBASE-3946 broke TestMasterFailover HBASE-3995 HBASE-3946 broke TestMasterFailover
HBASE-3889 NPE in Distributed Log Splitting (Anirudh Todi) HBASE-3889 NPE in Distributed Log Splitting (Anirudh Todi)
HBASE-4000 You can't specify split points when you create a table in
the shell (Joey Echeverria)
IMPROVEMENTS IMPROVEMENTS
HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack) HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack)

View File

@ -51,6 +51,8 @@ module HBaseConstants
INTERVAL = 'INTERVAL' INTERVAL = 'INTERVAL'
CACHE = 'CACHE' CACHE = 'CACHE'
FILTER = 'FILTER' FILTER = 'FILTER'
SPLITS = 'SPLITS'
SPLITS_FILE = 'SPLITS_FILE'
# Load constants from hbase java API # Load constants from hbase java API
def self.promote_constants(constants) def self.promote_constants(constants)

View File

@ -142,24 +142,48 @@ module Hbase
# Start defining the table # Start defining the table
htd = org.apache.hadoop.hbase.HTableDescriptor.new(table_name) htd = org.apache.hadoop.hbase.HTableDescriptor.new(table_name)
splits = nil
# All args are columns, add them to the table definition # Args are either columns or splits, add them to the table definition
# TODO: add table options support # TODO: add table options support
args.each do |arg| args.each do |arg|
unless arg.kind_of?(String) || arg.kind_of?(Hash) unless arg.kind_of?(String) || arg.kind_of?(Hash)
raise(ArgumentError, "#{arg.class} of #{arg.inspect} is not of Hash or String type") raise(ArgumentError, "#{arg.class} of #{arg.inspect} is not of Hash or String type")
end end
# Add column to the table if arg.kind_of?(Hash) and (arg.has_key?(SPLITS) or arg.has_key?(SPLITS_FILE))
descriptor = hcd(arg, htd) if arg.has_key?(SPLITS_FILE)
if arg[COMPRESSION_COMPACT] unless File.exist?(arg[SPLITS_FILE])
descriptor.setValue(COMPRESSION_COMPACT, arg[COMPRESSION_COMPACT]) raise(ArgumentError, "Splits file #{arg[SPLITS_FILE]} doesn't exist")
end
arg[SPLITS] = []
File.foreach(arg[SPLITS_FILE]) do |line|
arg[SPLITS].push(line.strip())
end
end
splits = Java::byte[][arg[SPLITS].size].new
idx = 0
arg[SPLITS].each do |split|
splits[idx] = split.to_java_bytes
idx = idx + 1
end
else
# Add column to the table
descriptor = hcd(arg, htd)
if arg[COMPRESSION_COMPACT]
descriptor.setValue(COMPRESSION_COMPACT, arg[COMPRESSION_COMPACT])
end
htd.addFamily(descriptor)
end end
htd.addFamily(descriptor)
end end
# Perform the create table call if splits.nil?
@admin.createTable(htd) # Perform the create table call
@admin.createTable(htd)
else
# Perform the create table call
@admin.createTable(htd, splits)
end
end end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------

View File

@ -33,6 +33,8 @@ Examples:
hbase> # The above in shorthand would be the following: hbase> # The above in shorthand would be the following:
hbase> create 't1', 'f1', 'f2', 'f3' hbase> create 't1', 'f1', 'f2', 'f3'
hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true} hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
hbase> create 't1', 'f1', {SPLITS => ['10', '20', '30', '40']}
hbase> create 't1', 'f1', {SPLITS_FILE => 'splits.txt'}
EOF EOF
end end