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

时间:2016-07-01 15:11:47

标签: select hive partition

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

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

需要永远。但

hive> show partitions table

只需要一秒钟。

是否可以将show partitions table操作为text_string并执行以下操作:

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

1 个答案:

答案 0 :(得分:0)

我试过在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")