数仓开发常用hive命令

在做数仓开发或指标开发时,是一个系统工程,要处理的问题非常多,经常使用到下面这些hive命令:

内部表转外部表

alter table ${tablename} set tblproperties (‘EXTERNAL’=True’);

外部表转内部表

alter table ${tablename} set tblproperties (‘EXTERNAL’=False’);

显示分区

show partitions ${tablename};

创建分区

alter table ${tablename} add if not exists partition(dt=’2022-11-08′)

删除分区

alter table ${tablename} drop partition(dt=’2022-11-21′)

修改分区

alter table ${tablename} partition(dt=’2022-11-08′) rename to partition(dt=’2022-11-21′)

获取table详细描述信息、存储格式等

desc formatted ${tablename}

修改hive表路径

alter table ${tablename} set location ‘${warehouse.dir}’

hive加载本地数据到分区表

load data local inpath ‘/tmp/test.txt’ into table ${tablename} partition (dt=’2022-11-08′);

加载本地目录的数据到分区表

load data inpath ‘/tmp’  into table ${tablename}  partition (dt=’2022-11-08′);

排他锁解锁

set hive.support.concurrency=true;  

set hive.txn.manager = org.apache.hadoop.hive.ql.lockmgr.DummyTxnManager;

设置session具有Admin权限

set role admin;

授予所有权限给某个用户

grant all on ${dbName} to user {userName};

查看指定用户在所有库下面的权限

show grant user {userName};

查看指定用户在某个库的权限

show grant user {userName} on database {dbName};

 授予某个库的权限给某个用户

grant select on database {dbName} to user {userName};

grant insert on database {dbName} to user {userName};

grant update on database {dbName} to user {userName};

grant delete on database {dbName} to user {userName};

Hive赋予用户某表权限

grant create on database {dbName} to user {userName};

grant select on table 库名.表名 to user 用户名 ;

grant insert on table {dbName}.tableName to user {userName};

grant update on table {dbName}.tableName to user {userName};

grant delete on table {dbName}.tableName to user {userName};

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注