簡體   English   中英

如何調整配置單元以查詢元數據?

[英]How to tune hive to query metadata?

如果我在具有某些分區列的表上運行下面的配置單元查詢,我想確保配置單元不進行全表掃描,而只是從元數據本身中找出結果。 有什么辦法可以做到這一點?

Select max(partitioned_col) from hive_table ;

現在,當我運行此查詢時,它的啟動圖會減少任務,並且可以確定它在進行數據掃描,同時可以很好地從元數據本身中找出值。

每次更改數據時都要計算表統計信息。

ANALYZE TABLE hive_table PARTITION(partitioned_col) COMPUTE STATISTICS FOR COLUMNS;

啟用CBO和統計信息自動收集:

set hive.cbo.enable=true;
set hive.stats.autogather=true;

使用以下設置可以使用統計信息啟用CBO:

set hive.compute.query.using.stats=true;
set hive.stats.fetch.partition.stats=true;
set hive.stats.fetch.column.stats=true;

如果沒有幫助, 我建議您采用這種方法快速找到最后一個分區:使用表位置中的shell腳本解析最大分區鍵。 下面的命令將打印所有表文件夾路徑,排序,采用最新排序,采用最后一個子文件夾名稱,解析分區文件夾名稱並提取值。 您只需要初始化TABLE_DIR變量並將the number of partition subfolder in the path放在the number of partition subfolder in the path

last_partition=$(hadoop fs -ls $TABLE_DIR/* | awk '{ print $8 }' | sort -r | head -n1 | cut -d / -f [number of partition subfolder in the path here] | cut -d = -f 2

然后使用$last_partition變量傳遞給您的腳本為

  hive -hiveconf last_partition="$last_partition" -f your_script.hql

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM