복붙노트

[HADOOP] 하이브 : SELECT AS 및 GROUP BY

HADOOP

하이브 : SELECT AS 및 GROUP BY

나는 하이브 쿼리를 좋아해.

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;

위의 쿼리가 오류와 함께 실패합니다.

'LoggerTable'은 문자열 형식의 모든 열이 포함 된 하이브 테이블입니다.

이 문제의 해결 방법은 무엇입니까?

해결법

  1. ==============================

    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;
    
  2. ==============================

    2.Hive 0.11.0 이상에서는 hive.groupby.orderby.position.alias가 true로 설정된 경우 열을 위치별로 지정할 수 있습니다. 다음 쿼리가 효과가 있는지 확인하십시오.

    Hive 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;
    
  3. from https://stackoverflow.com/questions/12600049/hive-select-as-and-group-by by cc-by-sa and MIT license