Skip to content
Advertisement

Hive: group by calculated column

I need to execute query like

select 
myUsualField, SOME_FUNCTION(myAnotherField) as myUnusualField 
from MYTABLE
group by 
myUsualField, myUnusualField 

In Hive this query fails: it cannot find field myUnusualField among other fields of the table.

Does this mean that in order to group by any calculated column in Hive I have to use subqueries?

select * from (
    select 
    myUsualField, SOME_FUNCTION(myAnotherField) as myUnusualField 
    from MYTABLE
) sourceTable
    group by 
    myUsualField, myUnusualField 

?

Advertisement

Answer

Try repeating the expression:

select myUsualField, SOME_FUNCTION(myAnotherField) as myUnusualField 
from MYTABLE
group by myUsualField, SOME_FUNCTION(myAnotherField) ; 
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement