无法在hive查询中添加列

时间:2013-05-15 08:32:51

标签: hadoop hive

CREATE EXTERNAL TABLE old_events
(day STRING, foo STRING, count STRING, internal_id STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LOCATION '${INPUT}';;

CREATE EXTERNAL TABLE events
(internal_id, foo STRING, count STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LOCATION '${OUTPUT}';;

INSERT OVERWRITE TABLE events
SELECT internal_id, e2.foo, count(e1.foo)
FROM old_events e2
LEFT OUTER JOIN old_events e1
ON e1.foo = e2.foo
WHERE e1.event = 'event1'
AND e2.event = 'event2'
GROUP BY e2.foo;

如果internal_id是select子句的一部分,则会出现以下错误     FAILED:语义分析出错:第5行:8表达式不在按键内部的内部元素

为了避免这种情况,我将internal_id添加到GROUP BY列,导致以下错误。     FAILED:语义分析错误:在多个表/子查询中找到列internal_id

如何解决此问题?

1 个答案:

答案 0 :(得分:3)

Brisi e1,e2都有列internal_id 所以你必须指出你想要的列 例如:

INSERT OVERWRITE TABLE events
SELECT e2.internal_id, e2.foo, count(e1.foo)
FROM old_events e2
LEFT OUTER JOIN old_events e1
ON e1.foo = e2.foo
AND e1.event = 'event1'
WHERE e2.event = 'event2'
GROUP BY e2.internal_id, e2.foo;