HIVE QL: How do I extract info from "show partitions table' and use it in a query?

馋奶兔 提交于 2019-12-10 18:03:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!