我尝试在论坛上进行搜索,在论坛上可以从现有的hbase表架构创建一个新的空hbase表,但找不到。
更准确地说,假设我有一个包含多个列族的表,并且这些族中有许多列限定符。
现在,我必须创建另一个具有相同架构的空表。我们是否可以像在RDBMS中一样创建表?
Create table new_table as
select * from existing_table where 1=2;
现有的表具有复杂的结构,因此不能使用指定了列族和列限定符的常规hbase
create table
命令。仅供引用。.我正在使用
Mapr HBase 0.98.12-mapr-1506
,但没有选择切换到任何高级版本或其他发行版的选项。 最佳答案
这是我使用的完全验证方法。希望它能对其他人有所帮助。
1)在命令下面启动HBase Shell sample 瓶
hbase shell
2)使用以下命令查询现有表元数据
hbase> describe ‘existing_table’;
输出将类似于:
{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)将此输出复制到记事本中,并进行以下更改:
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)最后运行带有新表名的创建查询:
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'}
这样就完成了。新表架构与现有表完全相同。
关于hadoop - HBase:使用与现有表相同的架构创建表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35596976/