hive常用命令

2021-09-01 23:33:14 字數 2395 閱讀 5292

[b]1.把內部表設定成外部表:[/b]

alter table table_name set tblproperties ('external'='true');

[b]2.檢視hadoop的hdfs檔案[/b]

hadoop fs -text | more

[b]3.檢視外部表資訊[/b]

describe extended table_name

[b]4.建立外部表[/b]

create external table if not exists table_name(id int,name string)

partitioned by(day string)

row format delimited fields terminated by '|';

[b]5.載入hdfs資料到表中[/b]

[b]6.檢視分割槽[/b]

show partitions tb_test;

[b]新增分割槽[/b]

[b]刪除分割槽[/b]

alter table login drop if exists partition (dt='2008-08-08');

alter table drop partition 來刪除分割槽。分割槽的元資料和資料將被一併刪除

[b]7.載入資料到指定分割槽表[/b]

load data local inpath'/root/hcr/tmp/sample.txt' into table tb_test partition(ds='2013-12-06',ds2='shanghai')

[b]8.修改表名rename to[/b]

alter table tb_records_ctas rename totb_records_2

[b]9.增加新列[/b]

alter table tb_records_2 add columns(new_col int);

[b]10.修改某一列的資訊[/b]

alter table tb_records_2 change column new_col col1 string;

[b]11.資料匯出[/b]

[b]匯出到本地目錄[/b]

insert overwrite local directory'/root/hcr/tmp/ex_abc2.txt' select * from m_t2;

[b]匯出到hdfs目錄[/b]

insert overwrite directory'/user/houchangren/tmp/m_t2' select * from m_t2;

[b]11.1 hive 匯出資料[/b]

bin/hive -e "select * from table" >> res.csv

[b]12.用jdbc連線hive之前一定要啟動hiveserver;命令:[/b]

hive -service hiveserver &

hive --service metastore -----------startup hive embedded

bin/hive --service hiveserver-----------startup hive standalone

[b]13.hive部分優化[/b]

[b]hive查詢limit優化[/b]

set hive.limit.optimize. enable=true;

[b]hive資料傾斜優化[/b]

set hive.groupby.skewindata=true;

[b]14.採用rcfile 方式壓縮歷史資料。fackbook全部hive表都用rcfile存資料。[/b]

[b]二、區域性壓縮方法[/b]

只需要兩步:

[b]1.建立表時指定壓縮方式,預設不壓縮,以下為示例:[/b]

create external table track_hist(

id bigint, url string, referer string, keyword string, type int, gu_idstring,

…/*此處省略中間部分字段*/ …, string,ext_field10 string)

partitioned by (ds string) stored as rcfile location '/data/share/track_histk' ;

[b]2.插入資料是設定立即壓縮[/b]

set hive.exec.compress.output=true;

insert overwrite table track_histpartition(ds='2013-01-01')

select id,url, …/*此處省略中間部分字段*/ …, ext_field10 fromtrackinfo

where ds='2013-01-01';

hive常用命令

進入hive目錄後執行hive命令進入命令模式 建立新錶 hive create table t hive a int,b int,c int row format delimited fields terminated by t 匯入資料t hive.txt到t hive表 hive load d...

hive常用命令

建立新錶 hive create table t hive a int,b int,c int row format delimited fields terminated by t 匯入資料t hive.txt到t hive表 hive load data local inpath home co...

Hive常用命令

檢視hdfs路徑 show create table table name 建表 create table tbname var1 char type1,var2 char type2 載入資料到表 刪除表 drop table tbname if expr1,expr2,expr3 expr1 判...