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_async.rb =================================================================== --- src/main/ruby/shell/commands/create_async.rb (revision 0) +++ src/main/ruby/shell/commands/create_async.rb (revision 0) @@ -0,0 +1,51 @@ +# +# Copyright 2010 The Apache Software Foundation +# +# 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 CreateAsync < Command + def help + return <<-EOF +Create table; pass table name, a dictionary of specifications per +column family, and optionally a dictionary of table configuration. +Dictionaries are described below in the GENERAL NOTES section. +Examples: + + hbase> create_async 't1', {NAME => 'f1', VERSIONS => 5} + hbase> create_async 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'} + hbase> # The above in shorthand would be the following: + hbase> create_async 't1', 'f1', 'f2', 'f3' + hbase> create_async 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true} + hbase> create_async 't1', 'f1', {SPLITS => ['10', '20', '30', '40']} + hbase> create_async 't1', 'f1', {SPLITS_FILE => 'splits.txt'} + +Note: This call is performed asynchronously - it returns right away, while + the servers are still working on creating and enabling the table. +EOF + end + + def command(table, *args) + format_simple_command do + admin.create(table, true, *args) + end + end + end + end +end 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