Hive:读取子选择中定义的表分区

问题描述

我有一个由 partitionDate 字段分区的 Hive 表。 我可以通过简单的方式读取我选择的分区

select * from myTable where partitionDate = '2000-01-01'

我的任务是动态指定我选择的分区。 IE。首先我想从某个表中读取它,然后才运行 select 到 myTable。当然,我想要使用分区的力量。

我写了一个查询,看起来像

select * from myTable mt join thatTable tt on tt.reportDate = mt.partitionDate

查询有效,但看起来没有使用分区。查询时间过长。

我尝试了另一种方法

select * from myTable where partitionDate in (select reportDate from thatTable)

.. 我再次发现查询运行速度太慢。

有没有办法在 Hive 中实现这一点?

更新:为 myTable 创建表

CREATE TABLE `myTable`(            
  `theDate` string,')            
PARTITIONED BY (           
  `partitionDate` string) 
TBLPROPERTIES (             
  'DO_NOT_UPDATE_STATS'='true','STATS_GENERATED_VIA_STATS_TASK'='true','spark.sql.create.version'='2.2 or prior','spark.sql.sources.schema.numPartCols'='1','spark.sql.sources.schema.numParts'='2','spark.sql.sources.schema.part.0'='{"type":"struct","fields":[{"name":"theDate","type":"string","nullable":true}...         
  'spark.sql.sources.schema.part.1'='{"name":"partitionDate","nullable":true}...','spark.sql.sources.schema.partCol.0'='partitionDate')  

解决方法

如果您在 Tez 执行引擎上运行 Hive,请尝试

radio_button

阅读 Jira HIVE-7826 中的更多详细信息和相关配置

同时尝试重写为LEFT SEMI JOIN:

set hive.tez.dynamic.partition.pruning=true;

如果没有任何帮助,请参阅此解决方法:https://stackoverflow.com/a/56963448/2700344

或者这个:https://stackoverflow.com/a/53279839/2700344

类似问题:Hive Query is going for full table scan when filtering on the partitions from the results of subquery/joins