I tried searching on the forum, where I can create a new empty hbase table from existing hbase table schema, but not able to find.
To be more precise, suppose I have a table with multiple column families and many column qualifier within those families.
Now I have to create another empty table with the same schema. Do we any way to create table like we do in RDBMS.
Create table new_table as
select * from existing_table where 1=2;
The existing table has a complex structure, so normal hbase create table
command with column family and column qualifier specified is not an option.
FYI.. I am using Mapr HBase 0.98.12-mapr-1506
and I do not have option to switch to any advance version or another distribution.
Here is the full-proof approach, I used. Hope it will help other people.
1) launch HBase shell vial below command
hbase shell
2) Query existing table metadata with below command
hbase> describe ‘existing_table’;
Output would be similar to:
{NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING
=> 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION
_SCOPE => '0'}
{NAME => 'cf2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING
=> 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION
_SCOPE => '0'}
3) Copy this output to a notepad and do below changes:
a) Replace TTL => 'FOREVER' with TTL => org.apache.hadoop.hbase.HConstants::FOREVER
b) Put an additional comma (,) between each column family description to connect column family definition.
c) Remove newline characters (\n, \r) for the text; such that the content become one line text.
4) Finally running the create query with new table name:
create ‘copy_of_exsting_table_schema’, {NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING
=> 'NONE', TTL => org.apache.hadoop.hbase.HConstants::FOREVER, COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION
_SCOPE => '0'} ,{NAME => 'cf2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING
=> 'NONE', TTL => org.apache.hadoop.hbase.HConstants::FOREVER, COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION
_SCOPE => '0'}
And you are done. The new table schema is exactly same as existing table.