Index: src/main/ruby/hbase/admin.rb =================================================================== --- src/main/ruby/hbase/admin.rb (revision 1139502) +++ src/main/ruby/hbase/admin.rb (working copy) @@ -154,7 +154,7 @@ #---------------------------------------------------------------------------------------------- # Creates a table - def create(table_name, *args) + def create(table_name, async_mode, *args) # Fail if table name is not a string raise(ArgumentError, "Table name must be of type String") unless table_name.kind_of?(String) @@ -167,6 +167,9 @@ # Start defining the table htd = org.apache.hadoop.hbase.HTableDescriptor.new(table_name) splits = nil + splitsStartKey = nil + splitsEndKey = nil + splitsNumRegions = nil # Args are either columns or splits, add them to the table definition # TODO: add table options support args.each do |arg| @@ -174,7 +177,8 @@ raise(ArgumentError, "#{arg.class} of #{arg.inspect} is not of Hash or String type") end - if arg.kind_of?(Hash) and (arg.has_key?(SPLITS) or arg.has_key?(SPLITS_FILE)) + if arg.kind_of?(Hash) and (arg.has_key?(SPLITS) or arg.has_key?(SPLITS_FILE) or + arg.has_key?(SPLITS_START_KEY)) if arg.has_key?(SPLITS_FILE) unless File.exist?(arg[SPLITS_FILE]) raise(ArgumentError, "Splits file #{arg[SPLITS_FILE]} doesn't exist") @@ -185,12 +189,20 @@ end end + if (arg.has_key?(SPLITS)) splits = Java::byte[][arg[SPLITS].size].new idx = 0 arg[SPLITS].each do |split| splits[idx] = split.to_java_bytes idx = idx + 1 end + end + + if (arg.has_key?(SPLITS_START_KEY)) + splitsStartKey = arg[SPLITS_START_KEY] + splitsEndKey = arg[SPLITS_END_KEY] + splitsNumRegions = arg[SPLITS_NUM_REGIONS] + end else # Add column to the table descriptor = hcd(arg, htd) @@ -201,14 +213,17 @@ end end - if splits.nil? - # Perform the create table call - @admin.createTable(htd) + unless splitsStartKey.nil? + @admin.createTable(htd, org.apache.hadoop.hbase.util.Bytes.toBytes(splitsStartKey), + org.apache.hadoop.hbase.util.Bytes.toBytes(splitsEndKey), splitsNumRegions) + else + if async_mode + @admin.createTableAsync(htd, splits) else - # Perform the create table call @admin.createTable(htd, splits) end end + end #---------------------------------------------------------------------------------------------- # Closes a region Index: src/main/ruby/hbase.rb =================================================================== --- src/main/ruby/hbase.rb (revision 1139502) +++ src/main/ruby/hbase.rb (working copy) @@ -53,6 +53,9 @@ FILTER = 'FILTER' SPLITS = 'SPLITS' SPLITS_FILE = 'SPLITS_FILE' + SPLITS_START_KEY = 'SPLITS_START_KEY' + SPLITS_END_KEY = 'SPLITS_END_KEY' + SPLITS_NUM_REGIONS = 'SPLITS_NUM_REGION' # Load constants from hbase java API def self.promote_constants(constants) Index: src/main/ruby/shell/commands/create.rb =================================================================== --- src/main/ruby/shell/commands/create.rb (revision 1139502) +++ src/main/ruby/shell/commands/create.rb (working copy) @@ -35,12 +35,14 @@ 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'} + hbase> create 't1', 'f1', {SPLITS_START_KEY => 'aaa', SPLITS_END_KEY = > 'zzz', \ + SPLITS_NUM_REGIONS => 10} EOF end def command(table, *args) format_simple_command do - admin.create(table, *args) + admin.create(table, false, *args) end end end Index: src/main/ruby/shell.rb =================================================================== --- src/main/ruby/shell.rb (revision 1139502) +++ src/main/ruby/shell.rb (working copy) @@ -216,6 +216,7 @@ :commands => %w[ alter create + create_async describe disable disable_all