【问题标题】:HIVE QL: How do I extract info from "show partitions table' and use it in a query?HIVE QL:如何从“显示分区表”中提取信息并在查询中使用它?
【发布时间】:2016-11-04 01:31:39
【问题描述】:

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

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')

【问题讨论】:

    标签: select hive partition


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多