我使用以下hive查询脚本的版本0.13.0
DROP TABLE IF EXISTS movies.movierating; DROP TABLE IF EXISTS movies.list; DROP TABLE IF EXISTS movies.rating; DROP DATABASE IF EXISTS movies; ADD JAR /usr/local/hadoop/hive/hive/lib/RegexLoader.jar; CREATE DATABASE IF NOT EXISTS movies; CREATE EXTERNAL TABLE IF NOT EXISTS movies.list (id STRING, name STRING, genre STRING) ROW FORMAT SERDE 'com.cisco.hadoop.loaders.RegexSerDe'with SERDEPROPERTIES( "input.regex"="^(.*)\\:\\:(.*)\\:\\:(.*)$", "output.format.string"="%1$s %2$s %3$s"); CREATE EXTERNAL TABLE IF NOT EXISTS movies.rating (id STRING, userid STRING, rating STRING, timestamp STRING) ROW FORMAT SERDE 'com.cisco.hadoop.loaders.RegexSerDe' with SERDEPROPERTIES( "input.regex"="^(.*)\\:\\:(.*)\\:\\:(.*)\\:\\:(.*)$", "output.format.string"="%1$s %2$s %3$s %4$s"); LOAD DATA LOCAL INPATH 'ml-10M100K/movies.dat' into TABLE movies.list; LOAD DATA LOCAL INPATH 'ml-10M100K/ratings.dat' into TABLE movies.rating; CREATE TABLE movies.movierating(id STRING, name STRING, genre STRING, rating STRING); INSERT OVERWRITE TABLE movies.movierating SELECT list.id, list.name, list.genre, rating.rating from movies.list list LEFT JOIN movies.rating rating ON (list.id=rating.id) GROUP BY list.id;
问题是当我执行没有"GROUP BY"子句的脚本时,它工作正常.但是当我使用"GROUP BY"子句执行它时,我收到以下错误
FAILED: SemanticException [Error 10002]: Line 4:21 Invalid column reference 'name'
有什么想法在这里发生了什么?
感谢您的帮助
谢谢!
如果按列分组,则select语句只能选择a)该列,b)仅从该列派生的列,或c)应用于其他列的UDAF.
在这种情况下,您只是按list.id进行分组,因此当您尝试选择list.name时,这是无效的.想一想:如果您的列表包含以下两个条目,该怎么办:
id|name |genre --+-----+------ 01|name1|comedy 01|name2|horror
您期望此查询返回什么:
select list.id, list.name, list.genre from list group by list.id;
在这种情况下,它是荒谬的.我猜测现实中的id是主键,但请注意,hive不知道这一点,因此上述数据集完全有效.
考虑到所有这些,我不清楚如何解决它,因为我不知道所需的输出.例如,假设没有group by(只是连接),你有输出:
id|name |genre |rating --+-----+------+------- 01|name1|comedy|'pretty good' 01|name1|comedy|'bad' 02|name2|horror|'9/10' 03|name3|action|NULL
你希望输出与群组一起出现什么?你想通过小组做什么来完成什么?