Hive常用命令總結
阿新 • • 發佈:2018-12-25
1.建表
建表(預設是內部表)
create table trade_detail(id bigint, account string, income double, expenses double, time string)
row format delimited fields terminated by '\t';
建分割槽表
普通表和分割槽表區別:有大量資料增加的需要建分割槽表
create table td_part(id bigint, account string, income double, expenses double, time string)
partitioned by (logdate string)
row format delimited fields terminated by '\t';
建外部表
create external table td_ext(id bigint, account string, income double, expenses double, time string)
row format delimited fields terminated by '\t' location '/td_ext';
2.載入資料到表
把本地資料裝載到資料表,也就是在metastore上建立資訊
load data local inpath '/root/a.txt' into table trade_detail;
把HDFS上的資料裝載到資料表
load data inpath '/target.txt' into table trade_detail;
載入資料到分割槽表必須指明所屬分割槽
load data local inpath './book.txt' overwrite into table book
partition (pubdate='2010-08-22');
3.Hive 的shell下可以執行HDFS和Linux命令:
在Hive shell下執行hadoop命令列:
比如:hadoop fs -ls /,在hive下可以這樣執行:
hive> dfs -ls /;
在Hive shell下執行linux系統命令:
!cmd;
例如:!pwd;列印當前工作目錄
在Hive shell下執行sql檔案:
hive> source my.sql;
hive -S 以靜默模式啟動hive(不列印日誌資訊,紙列印結果);
hive -e “HiveQL”,不進入hive的互動模式,直接執行命令;
當然也可以結合靜默模式一起使用:
hive -S -e “HiveQL”
4.另外一些常用的命令其實就是SQL:
描述表結構
desc tablename;
檢視建立表資訊
show create table tablename;
查看錶的分割槽
show partitions tablename;