蜂巢:SELECT AS和GROUP BY(Hive: SELECT AS and GROUP BY

2019-07-31 23:08发布

我有一个蜂巢状查询

SELECT Year, Month, Day, Hours, Minutes,
           cast((cast(Seconds as int)/15) as int)*15
AS secondMod, Count(*) AS PerCount FROM LoggerTable 
 GROUP BY Year, Month, Day, Hours, Minutes, secondMod 
ORDER BY PerCount;

上述查询失败,错误

FAILED:错误在语义分析:第1行:175无效表别名或列引用secondMod

“LoggerTable”是一个蜂巢表与字符串类型的所有列。

任何办法解决这个问题?

Answer 1:

试试这个:

SELECT Year, Month, Day, Hours, Minutes, 
cast((cast(Seconds as int)/15) as int)*15 
AS secondMod, Count(*) AS PerCount FROM LoggerTable 
 GROUP BY Year, Month, Day, Hours, Minutes, 
   cast((cast(Seconds as int)/15) as int)*15
ORDER BY PerCount;


Answer 2:

在蜂巢0.11.0后来,列可以通过位置来指定,如果hive.groupby.orderby.position.alias设置为true 。 请确认以下查询你的作品。

SET hive.groupby.orderby.position.alias=true;
SELECT Year
       ,Month
       ,Day
       ,Hours
       ,Minutes
       ,cast((cast(Seconds as int)/15) as int)*15 AS secondMod
       ,count(*) AS PerCount 
FROM LoggerTable 
GROUP BY 1, 2, 3, 4, 5, 6
ORDER BY 7;


文章来源: Hive: SELECT AS and GROUP BY
标签: hadoop hive