Hive 分區表創建,增加,刪除

Hive分區表

 

1.從HDFS加載數據

A.建表時加載

hive -e "create table if not exists tableName
str1 string,
str2 string,
str3 string
)
partitioned by (dt string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE"
LOCATION '/user/xxx/xxx/xxx';

需注意格式與Hive表字段保持一致 且 文件命名按dt=xxxx格式

B.建表後加載

hive -e "ALTER TABLE tableName ADD PARTITION(dt=20200202) LOCATION '/user/xxx/xxx/dt=20200202';"

 

2.從Hive表到Hive表

hive -e "create table if not exists tableName
str1 string,
str2 string,
str3 string
)
partitioned by (dt string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE
insert into table tableName partition(dt=$day)
select xxx,yyy,zzz from XXX”

同樣需要注意格式 和 字段

 

3.刪除分區

hive -e "alter table tableName drop partition(partition_key=20200202);"

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章