[英]How to know location about partition in hive?
如果我寫一個 hive sql 就像
ALTER TABLE tbl_name ADD PARTITION (dt=20131023) LOCATION 'hdfs://path/to/tbl_name/dt=20131023;
稍后如何查詢有關分區的此位置? 因為我發現位置有一些數據但我無法查詢它們,hive sql like
SELECT data FROM tbl_name where dt=20131023;
對分區而不是全表進行描述。
如果它是外部表,這將顯示鏈接的位置。
describe formatted tbl_name partition (dt='20131023')
show table extended like 'tbl_name' partition (dt='20131023');
SHOW TABLE EXTENDED
將列出與給定正則表達式匹配的所有表的信息。 如果存在分區規范,則用戶不能對表名使用正則表達式。 此命令的輸出包括像基本表信息和文件系統信息totalNumberFiles
,totalFileSize
,maxFileSize
,minFileSize
,lastAccessTime
和lastUpdateTime
。 如果分區存在,它將輸出給定分區的文件系統信息而不是表的文件系統信息。
如果您有多個嵌套分區,則語法為:
describe formatted table_name partition (day=123,hour=2);
這是我用來獲取特定表中特定分區的確切 HDFS 位置的命令格式:
show table extended like flight_context_fused_record partition(date_key='20181013', partition_id='P-DUK2nESsv', custom_partition_1='ZMP');
在上面的命令中,分區規范由三個單獨的字段組成。 你的例子可能有更多或更少。
請參閱下面的結果。 請注意“位置:”字段顯示 HDFS 文件夾位置。
hive (nva_test)> show table extended like flight_context_fused_record partition(date_key='20181013', partition_id='P-DUK2nESsv', custom_partition_1='ZMP');
OK
tableName:flight_context_fused_record
owner:nva-prod
location:hdfs://hdp1-ha/tmp/vfisher/cms-context-acquisition-2019-06-13/FlightContextFusedRecord/2018/10/13/ZMP/P-DUK2nESsv
inputformat:org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat
outputformat:org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat
columns:struct columns { string primary_key, string facility, string position, i32 dalr_channel, i64 start_time_unix_millis, i64 end_time_unix_millis, string foreign_key_to_audio_segment, struct<on_frequency_flight_list:list<struct<acid:string,ac_type:string>>,transfer_list:list<struct<primary_key:string,acid:string,data_id:string,ac_type:string,from_facility:string,from_position:string,transition_time:i64,transition_time_start:i64,transtition_time_end:i64,to_facility:string,to_position:string,source:string,source_info:string,source_time:i64,confidence:double,confidence_description:string,uuid:string>>,source_list:list<string>,domain:string,domains:list<string>> flight_context}
partitioned:true
partitionColumns:struct partition_columns { i32 date_key, string partition_id, string custom_partition_1}
totalNumberFiles:1
totalFileSize:247075687
maxFileSize:247075687
minFileSize:247075687
lastAccessTime:1561122938361
lastUpdateTime:1561071155639
命令的通用形式(取出我的特定值並放入參數說明符)如下所示:
show table extended like <your table name here> partition(<your partition spec here>);
如果您想知道正在閱讀的文件的位置,請使用
SELECT INPUT__FILE__NAME, BLOCK__OFFSET__INSIDE__FILE FROM <table> WHERE <part_name> = '<part_key>'
然后你得到
hdfs:///user/hive/warehouse/<db>/<table>/<part_name>=<part_key>/000000_0.snappy, 0
hdfs:///user/hive/warehouse/<db>/<table>/<part_name>=<part_key>/000000_1.snappy, 0
你可以簡單地這樣做:
DESC FORMATTED tablename PARTITION (yr_no='y2019');
OR
DESC EXTENDED tablename PARTITION (yr_no='y2019');
您可以通過運行以下任何 Hive 命令來獲取 HDFS 上 Hive 分區的位置。
DESCRIBE FORMATTED tbl_name PARTITION(dt=20131023);
SHOW TABLE EXTENDED LIKE tbl_name PARTITION(dt=20131023);
或者,您也可以通過運行 HDFS list 命令來獲取
hdfs dfs -ls <your Hive store location>/<tablename>
鏈接: Hive 顯示或列出所有分區
謝謝,NNK
您可以通過 Hive Metastore Thrift 協議獲取此信息,例如使用hmsclient 庫:
蜂巢cli:
hive> create table test_table_with_partitions(f1 string, f2 int) partitioned by (dt string);
OK
Time taken: 0.127 seconds
hive> alter table test_table_with_partitions add partition(dt=20210504) partition(dt=20210505);
OK
Time taken: 0.152 seconds
Python命令行:
>>> with client as c:
... partition = c.get_partition_by_name(db_name='default',
tbl_name='test_table_with_partitions',
part_name='dt=20210504')
...
>>> partition.sd.location
'hdfs://hdfs.master.host:8020/user/hive/warehouse/test_table_with_partitions/dt=20210504'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.