HIVE QL:我如何从“show partitions table”中提取信息并在查询中使用它? [英] HIVE QL: How do I extract info from "show partitions table' and use it in a query?
本文介绍了HIVE QL:我如何从“show partitions table”中提取信息并在查询中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我想从大表中选择上个月时,我可以这样做:
select *
从表
其中yyyymm =(从表中选择max(yyyymm))
。但是
hive>显示分区表
只需要一秒钟。
将显示分区表
操纵到text_string中并执行如下操作:
select *
from table
where yyyymm =(manipulated'partition_txt')
<我试过在Hive中做这件事,但无法做到,所以我在Spark 2.1.1中做了这件事。
val part = spark.sql(SHOW PARTITIONS db.table)
//将列表反向排序并写入hdfs myDir
part.sort(col (partition).desc).write.csv.save(myDir)
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')
解决方案
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")
这篇关于HIVE QL:我如何从“show partitions table”中提取信息并在查询中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文