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

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

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
WHERE e1.event = 'event1'
AND e2.event = 'event2'
AND ds = date_sub('${DAY}',1)
GROUP BY e2.internal_id, e2.foo;

失败:语义分析错误:在多个表/子查询中发现 ds 列

添加获取当前日期的 ds 变量时出现此错误。我如何使用上述脚本实现日期分区。

4

1 回答 1

10

您需要dsWHERE子句中添加别名。例如,ds = date_sub('${DAY}',1)e2.ds = date_sub('${DAY}',1)

为了稍微澄清您的问题,这是一个较小的示例,它显示了相同的行为

CREATE EXTERNAL TABLE example
(a INT, b INT)
LOCATION '${OUTPUT}';

SELECT *
FROM example e1
JOIN example e2
  ON e1.a = e2.a
WHERE b = 5;

这会产生相同的错误:

FAILED: SemanticException Column b Found in more than One Tables/Subqueries

问题是该列b存在于example别名为e1e2中。你和我可能知道,如果你example在列上加入自身,那么a它应该不需要别名,但 Hive 不知道这一点,所以你需要选择一个来消除任何歧义。此处是否为分区列并不重要。e1.be2.bb

于 2013-05-17T15:01:50.950 回答