问题
When I want to select the last month from a big table I can do this:
select *
from table
where yyyymm=(select max(yyyymm) from table)
It takes forever. But
hive> show partitions table
only takes a second.
Would it be possible to manipulate show partitions table into a text_string and do something like:
select *
from table
where yyyymm=(manipulated 'partition_txt')
回答1:
I tried doing this in Hive but couldn't, so I did it in 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")
来源:https://stackoverflow.com/questions/38148763/hive-ql-how-do-i-extract-info-from-show-partitions-table-and-use-it-in-a-quer