本人常用的hive命令:
1.不用启动hive就能运行建表语句
hive -f xx.sql ;
注意:建表语句如果是外部编译器编写的话要更改编码格式为
要不会爆这个错误
2.添加列
alter table dev_odb.cac_am_aa_maint_hist add columns (increment_id bigint);
3.获取建表语句
show create table xx;
4.查看表有哪些分区
show partitions xx表;
5.hive模糊搜索表
show tables like '*name*';
6.查看表结构信息
desc formatted table_name;
desc table_name;
7.根据分区查看数据
select * from xx表 where partition_name='xx';
8.更改表的注释
ALTER TABLE 表名 SET TBLPROPERTIES('comment' = '(旧)担保合同基本信息表');
更改列的注释,这个语句同时能更改列名,列类型,和注释
alter table xx表 change column 列名 新的列名 新的列类型 comment '新的注释';
eg:alter table ll change column o oo int comment '的';
9.把hive数据查到下载到本地服务中
insert overwrite local directory '/root/a' select * from a;
不加local是把查到的数据放到hdfs文件目录中
10.加载数据到hive表中
load data (local) inpath '数据文件的位置' (overwrite) into table xx表;
insert (overwrite) table xx表 select * from xxx表;//把xxx表中的数据加载到xx表中
11.在hive中查看hdfs文件信息
dfs -ls /root/a;
12.不启动hive执行hiveql
hive -e "select * from 表名";
13.把hive表查询的数据放到另一张hive表中
create table xx as select * form xxx;//把xxx表复制到xx表中
14.更改表的列名/把某一列改到第一列上
alter table 表名 change column 列名 列名 要更改的列类型;//更改列的类型
eg:alter table a change column test test bigint;
alter table 表名 change column 列名 列名 列名的类型 first;//把当前列放到第一个
eg:alter table test.a change column test test bigint first;//test.a是因为我use test库
15.删除表的分区
alter table xx表 drop if exists partition (分区名='条件');
16.查看hive表的分区信息
show partitions xx表;
17.添加表的分区