hiveql:如何从“show partitions table”中提取信息并在查询中使用它?

wz8daaqr  于 2021-06-29  发布在  Hive
关注(0)|答案(1)|浏览(514)

当我想从一个大表中选择上个月时,我可以这样做:

select *
from table
where yyyymm=(select max(yyyymm) from table)

这需要永远。但是

hive> show partitions table

只需要一秒钟。
有没有可能操纵 show partitions table 转换为文本字符串并执行以下操作:

select *
from table
where yyyymm=(manipulated 'partition_txt')
k75qkfdt

k75qkfdt1#

我试过在Hive里做这个,但是做不到,所以我在spark 2.1.1中做了。

val part = spark.sql("SHOW PARTITIONS db.table")
// sorts list in reverse and writes to hdfs myDir
part.sort(col("partition").desc).write.csv.save("myDir")

相关问题