简体   繁体   English

HBase:创建与现有表具有相同架构的表

[英]HBase: Create table with same schema as existing table

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.我尝试在论坛上搜索,在那里我可以从现有的 hbase 表模式创建一个新的空 hbase 表,但无法找到。

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.我们是否可以像在 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.现有表具有复杂的结构,因此指定列族和列限定符的普通 hbase create table命令不是一个选项。

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.仅供参考.. 我正在使用Mapr HBase 0.98.12-mapr-1506 ,我没有选择切换到任何高级版本或其他发行版。

Here is the full-proof approach, I used.这是我使用的完全证明方法。 Hope it will help other people.希望它能帮助其他人。

1) launch HBase shell vial below command 1)在命令下面启动HBase shell小瓶

 hbase shell

2) Query existing table metadata with below command 2)使用以下命令查询现有表元数据

 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: 3)将此输出复制到记事本并进行以下更改:

  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: 4) 最后使用新表名运行创建查询:

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.新表架构与现有表完全相同。

you can use snapshot feature to do this.您可以使用快照功能来做到这一点。 like this;像这样;

hbase> snapshot 'tableName', 'tableSnapshot'
hbase> clone_snapshot 'tableSnapshot', 'newTableName'
hbase> delete_snapshot 'tableSnapshot'
hbase> truncate 'newTableName'

i hope your table is not huge.我希望你的桌子不是很大。 And you can not copy column qualifiers with empty values, if i did not understand wrong, you mean this in your question.而且你不能用空值复制列限定符,如果我没有理解错,你的意思是在你的问题中。 you can either copy all data to new table or only table structure with column families, coprocessors.. etc.您可以将所有数据复制到新表或仅带有列族、协处理器等的表结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM