hive和hbase的建,删表命令

HIVE:
当删除一个库的时候 ,若库里面有表则提示不能删除

hive> drop database TABLENAME;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. InvalidOperationException(message:Database TABLENAME is not empty. One or more tables exist.)

此时用户可以先删除库里面的表,然后在删除数据库,或者使用在删除语句后面加关键字CASCADE来删除数据库

hive> drop database TABLENAME CASCADE;
OK
Time taken: 0.875 seconds

HBASE:
查看命名空间:

hbase> list_namespace

新建命名空间:

hbase> create_namespace 'ns1'

删除命名空间:

hbase> drop_namespace 'ns1'
该命名空间必须为空,否则会报错。
非空删除操作:
disable 'table.x'
drop 'table.x'
假如有一些表以tab开头,通过如下操作,可以将这些表全部删除:
disable_all 'tab.*'
drop_all 'tab.*'

修改命名空间:

hbase> alter_namespace 'ns', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}


列出所有表:

hbase> list

列出指定命名空间下的所有表

hbase> list_namespace_tables 'ns1'

新建表

hbase> create 'ns1:t1', 'cf1'

新建一个以命名空间ns1的表t1,列族为cf1。

删除表:

hbase> disable 'ns1:t1'
hbase> drop 'ns1:t1'

修改表名:
HBase没有rename命令,可以通过快照功能修改表名,详见下述。

查看表内容:

hbase> scan 'ns1:t1'
hbase> scan 'ns1:t1', {LIMIT=>5} # 查看前5行数据

插入:

hbase> put 'ns1:t1', 'r1', 'cf1:c1', 'value'

预分区:

create 'gld:student', 'cf1', {SPLITS => ['1', '2', '3', '4', '5', '6', '7', '8', '9']}
则每个分区的Start Key和End Key分别为:
(~, 1),[1, 2),[2, 3),[3, 4),[4, 5),[5, 6),[6, 7),[7, 8),[8, 9),[9, ~)

手动分区

一开始没有分区,使用切分键’1’一分为二:
hbase> split 'tableName', 'splitKey'
hbase> split 'gld:student', '1'  
继续将第二个Region进行切分,以’2’作为切分键:
hbase> split 'regionName', 'splitKey'
hbase> split 'gld:student,1,1538223641947', '2'  

合并分区

hbase> merge_region 'ENCODED_REGIONNAME', 'ENCODED_REGIONNAME'
hbase> merge_region 'eea56b5303ed9aca9aa2b4adc14798b8','e8324c9b047282a608588c8826484f5d'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值