hive-仅获取一个或多个配置单元表的最新分区

t5fffqht  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(481)

我在配置单元中有三个分区表(每年分区),所有表都有多个分区。作为我要求的一部分,我要加入这三张table。现在我只想为最新的分区运行这个sql,而不是为以前创建的分区运行这个sql。
我试图在where子句中使用max(partition),但似乎不受支持
我做了下面这样的事情(不是确切的代码。只是一个代码概念)

select
a.*,
b.*,
c.*
from table1 a
left join table2 b on a.ID = b.ID
left join table3 c on a.ID = c.ID
where
a.year = max(a.year) and
b.year = max(b.year) and
c.year = max(c.year)

我犯了这个错误
失败:semanticexception[error 10128]:行108:23尚未支持udaf“max”的位置
我可以使用多个where子句和包含“selectmax(year)fromtable”的子查询来表示所有表,但这似乎不是一个可行的子查询。有什么办法可以做到这一点吗?
更新我用下面的条件尝试了where子句,但是where子句似乎只支持一个suq查询。不知道如何解决这个问题。感谢您对此的任何意见

where
a.year in (select max(year) from table1) and
b.year in (select max(year) from table2) and
c.year in (select max(year) from table3
6vl6ewon

6vl6ewon1#

修改版本:

select
    <columns>
    from  
    (  
     select 
     <columns> 
     from 
     table1 a 
     where a.year in (select max(year) from table1) 
    ) a1
    left join 
    (
     select 
     <columns> 
     from 
     table2 b 
     where b.year in (select max(year) from table2) 
    ) b1 on a1.ID = b1.ID
    left join 
    (
     select 
     <columns> 
     from 
     table3 c 
     where c.year in (select max(year) from table3) 
    ) c1 on a1.ID = c1.ID
;

相关问题