1. 程式人生 > >Hive建Hdfs外部分割槽表

Hive建Hdfs外部分割槽表

1、目錄及資料準備
hadoop dfs -rmr /tmp/oss_access_test/2017-04-01
hadoop dfs -mkdir -p /tmp/oss_access_test/2017-04-01/
hadoop dfs -cp /tmp/oss_access/2017-04-01/sz-98-72_localhost_access_log.2017-04-01.*.txt /tmp/oss_access_test/2017-04-01/sz-98-72_localhost_access_log.2017-04-01.*.txt
或:
hadoop dfs -cp -p /tmp/oss_access/2017-04-01/ /tmp/oss_access_test/
hadoop dfs -ls /tmp/oss_access_test/2017-04-01/
--刪除資料不進回收站
hadoop dfs -rmr -skipTrash /tmp/oss_access_test/2017-04-01/*

2、建立外部表
drop table if exists xx_ext_oss_access;
create external table xx_ext_oss_access
(
log_text string
)
partitioned by(pt_day string)
row format delimited
fields terminated by ','
location '/tmp/oss_access_test/';

3、新增分割槽
alter table xx_ext_oss_access add partition(pt_day='2017-04-01') location '2017-04-01';

4、查詢測試
select * from xx_ext_oss_access limit 100;

5、注意說明
建表時的location後面路徑帶上"/",而分割槽上的location路徑直接帶分割槽相對路徑名“'2017-04-01'”就可以了。
分割槽表裡面的所有資料檔案不能再有資料夾,否則會較驗報錯。
另外,外部表進行drop table的時候,只是刪除表結構,而不會刪除對應的資料。