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'