Hive中建立S3的外部表

2021-09-07 18:37:40 字數 2446 閱讀 3661

hive中建立s3的外部表

資料在s3存放的資料是按時間緯度存放的,每天的資料存放在各自的目錄下,目錄結構如下截圖:

每個目錄下面的資料是csv檔案,現在將其匯入到hive中進行查詢,通過建立對應的表結構:    

[sql]view plain

copy

hadoop到s3

hadoop distcp hdfs:/user/hive/data/searchrecord/2014-02-16 s3n://*/hadoop/user/hive/data/searchrecord/2014-02-16 

需要在core-site.xml中配置好fs.s3n.awsaccesskeyid和fs.s3n.awssecretaccesskey

注意s3的路徑需要使用s3n

s3到hadoop

然後通過如下語句進行查詢:    

[sql]view plain

copy

select * from palmplay_log_pv_s3_csv limit 10;  

select * from palmplay_log_pv_s3_csv where dt='2018-04-09' limit 10;  

此時是查詢不到結果,因為這個時候分割槽表的分割槽資訊並沒有載入到hive的metastore中,需要先執行將分割槽資訊載入到metastore中,才可以查詢到資料。

載入表的分割槽資訊到metastore中

從s3中將表的分割槽資訊載入到hive的metastore中,這個同從hdfs中載入表的分割槽資訊是一樣的,執行以下命令進行載入:    

[plain]view plain

copy

msck repair table palmplay_log_pv_s3_csv;  

然後再執行select查詢就可以查詢到資料了。

注:可以使用hive.metastore.fshandler.threads引數(預設值為15,配置在hive-site.xml中)來增加用於在msck階段中掃瞄分割槽的執行緒數。

對錶進行分析

在amazon s3上處理資料時,分析表的步驟與在hdfs中處理資料時的步驟相同。

可以通過設定hive.stats.autogather = true或執行analyze table table_name compute statistics命令自動收集表統計資訊,例如:

analyze table table_name partition(dt ='2018-04-09')compute statistics;

但是,列統計資訊只能通過執行列命令的分析表測試計算統計資訊來收集,例如:    

[sql]view plain

copy

analyze table table_name partition(ds ='2018-04-09')columns;  

有關更多資訊和示例,請參閱apache文件。

hive操作s3資料

1 hive配置s3訪問許可權 2 建立表 例如create external table table create time bigint comment 獲取時的時間 event name string comment 事件名 timestamp bigint comment 事件發生時間 is...

Hive建立外部表

hive建立外部表 1.環境需求 hadoop 2.6.0 hive 1.2.1 hue 3.7.0 2.開發過程 1 建立hdfs目錄 hadoop dfs mkdir wy input 2 上傳本地資料到hdfs中 hadoop dfs put usr wy writing.txt wy inp...

HIVE建立外部表

基礎建表語句 create external table if not exists table name col name data type comment col comment comment table comment partitioned by col name data type c...