Skip to content

Instantly share code, notes, and snippets.

@mikelikespie
Created December 8, 2010 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikelikespie/733911 to your computer and use it in GitHub Desktop.
Save mikelikespie/733911 to your computer and use it in GitHub Desktop.
clones a table in hbase. Optionally takes an array of strings that are the keys to create the splits on
def clone_table(old_table_name, new_table_name, split_keys=nil)
admin = HBaseAdmin.new(HBaseConfiguration.new())
td = admin.getTableDescriptor(old_table_name.to_java_bytes)
td.setName(new_table_name.to_java_bytes)
if split_keys.nil?
admin.createTable(td)
else
new_keys = Java::byte[][split_keys.size].new
split_keys.each_index {|i| new_keys[i] = split_keys[i].to_java_bytes}
admin.createTable(td, new_keys)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment