我在hive查询中使用四级嵌套时遇到问题。下面是我正在执行的查询 -
SELECT *,
SUM(qtod.amount) OVER (PARTITION BY qtod.id, qtod.year_begin_date ORDER BY qtod.tran_date)
FROM (SELECT *,
SUM(mtod.amount) OVER (PARTITION BY mtod.id, mtod.quarter_begin_date ORDER BY mtod.tran_date)
FROM (SELECT *,
SUM(wtod.amount) OVER (PARTITION BY wtod.id, wtod.month_begin_date ORDER BY wtod.tran_date)
FROM (select id,
year_begin_date,
quarter_begin_date,
month_begin_date,
week_begin_date,
tran_date,
amount,
SUM(amount)
OVER (PARTITION BY id,week_begin_date ORDER BY tran_date) FROM table_name)wtod)mtod)qtod;
如果我排除了第四级嵌套,它工作正常,但在包含它时,低于错误消息 -
FAILED:SemanticException [错误10007]:不明确的列引用 qtod中的_c1
为避免嵌套,我试图以其他方式进行嵌套
SELECT * FROM
(SELECT id,year_begin_date,tran_date,amount,SUM(amount) OVER (PARTITION BY id,year_begin_date ORDER BY tran_date) FROM yeartodate)ytod
JOIN
(SELECT *, SUM(mtod.amount) OVER (PARTITION BY mtod.id, mtod.quarter_begin_date ORDER BY mtod.tran_date)
FROM (SELECT *, SUM(wtod.amount) OVER (PARTITION BY wtod.id, wtod.month_begin_date ORDER BY wtod.tran_date)
FROM (select id,
year_begin_date,
quarter_begin_date,
month_begin_date,
week_begin_date,
tran_date,
amount,
SUM(amount)
OVER (PARTITION BY id,week_begin_date ORDER BY tran_date) FROM table_name)wtod)mtod)qtod
ON qtod.id=ytod.id AND qtod.tran_date=ytod.tran_date;
错误仍然相同。
在网上搜索后,根据JIRA为蜂巢提出的问题,发现蜂巢本身就是一个问题
由于 jira已修复,而且补丁在hive 14 中可用,因此我尝试在hive 14(HDP)上运行它。
仍然得到相同的错误
请写下你的建议......
答案 0 :(得分:2)
SELECT
内的非别名函数调用映射到列名_c1
,_c2
等。在这种情况下,每个{{1}都有一个非别名函数调用所以他们都创建了一个列SELECT
。
问题在于,因为您正在从下一个子查询中执行_c1
,然后追加映射到SELECT *
的另一个函数调用,那么您将拥有两次相同的列,因此围绕模糊列引用的错误。
解决方案应该是对所有函数调用进行别名,以便它们不使用_c1
默认名称,如下所示:
_c1