![](/img/trans.png)
[英]Hive 0.14 on Tez : one file per insert, even with hive.merge. activated
[英]In hive how to insert data into a single file
從表1插入覆蓋目錄'wasb:/// hiveblob /'SELECT *; 這項工作有效,但是當我們發出諸如INSERT OVERWRITE DIRECTORY'wasb:///hiveblob/sample.csv'之類的命令時,請從表1中選擇*; 發生異常失敗無法重命名:wasb://incrementalhive-1@crmdbs.blob.core.windows.net/hive/scratch/hive_2015-06-08_10-01-03_930_4881174794406290153-1/-ext-10000至:wasb:/ hiveblob / sample.csv
因此,有什么方法可以將數據插入單個文件
我認為您不能告訴蜂巢直接寫入特定文件,例如wasb:///hiveblob/foo.csv
。
您可以做的是:
在運行查詢之前,告訴hive將輸出文件合並為一個。 這樣,您可以擁有任意數量的reduce,但仍然只有一個輸出文件。
運行您的查詢,例如INSERT OVERWRITE DIRECTORY ...
然后在hive中使用dfs -mv
將文件重命名為任何內容。
這可能比使用Ramzy建議的使用單獨的hadoop fs -getmerger /your/src/folder /your/dest/folder/yourFileName
。
根據您使用的運行時引擎,指示合並文件的方法可能會有所不同。
例如,如果在蜂巢查詢中使用tez
作為運行時引擎,則可以執行以下操作:
-- Set the tez execution engine
-- And instruct to merge the results
set hive.execution.engine=tez;
set hive.merge.tezfiles=true;
-- Your query goes here.
-- The results should end up in wasb:///hiveblob/000000_0 file.
INSERT OVERWRITE DIRECTORY 'wasb:///hiveblob/' SELECT * from table1;
-- Rename the output file into whatever you want
dfs -mv 'wasb:///hiveblob/000000_0' 'wasb:///hiveblob/foo.csv'
(以上版本對我適用於以下版本:HDP 2.2,Tez 0.5.2和Hive 0.14.0)
對於MapReduce引擎(默認設置),您可以嘗試這些,盡管我自己還沒有嘗試過:
-- Try this if you use MapReduce engine.
set hive.execution.engine=mr;
set hive.merge.mapredfiles=true;
默認情況下,您將有多個輸出文件,這些文件等於減速器的數量。 這是由Hive決定的。 但是,您可以配置減速器。 看這里 。 但是,如果我們減少減速器,則會降低性能,並且會花費更多的執行時間。 另外,一旦文件存在,您就可以使用get merge並將所有文件合並為一個文件。
hadoop fs -getmerger /您的/ src /文件夾/您的/目的地/文件夾/您的文件名。 src文件夾包含所有要合並的文件。
您可以通過強制將reducer強制為一個來強制配置單元來構建一個文件。 這會將所有碎片文件復制到一個表中,並將它們合並到HDFS的另一位置。 當然,強制使用一個減速器會破壞並行性的優勢。 如果您打算進行任何數據轉換,建議先進行此轉換,然后再在最后一個單獨的階段進行。
要使用配置單元生成單個文件,您可以嘗試:
set hive.exec.dynamic.partition.mode=nostrict;
set hive.exec.compress.intermediate=false;
set hive.exec.compress.output=false;
set hive.exec.reducers.max=1;
create table if not exists db.table
stored as textfiel as
select * from db.othertable;
db.othertable是具有多個碎片文件的表。 db.table將具有包含組合數據的單個文本文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.