Wrapping an analytical function in another function in Hive 0.11

hivehiveql

I am trying the following:

select case when ta_end_datetime_berekenen = 'Y' then lead(ta_update_datetime) over ( partition by dn_waarde_van, dn_waarde_tot order by ta_update_datetime ) else ea_end_datetime end ea_end_datetime, ta_insert_datetime, ta_update_datetime from tmp_wtdh_bestedingsklasse_10_s2_stap2

However, when I try that, I get the following error:

NoViableAltException(86@[129:7: ( ( ( KW_AS )? identifier ) | ( KW_AS LPAREN identifier ( COMMA identifier )* RPAREN ) )?])

FAILED: ParseException line 1:175 missing KW_END at 'over' near ')' in selection target
line 1:254 cannot recognize input near 'else' 'ea_end_datetime' 'end' in selection target

Would I be correct in assuming that it's not possible to wrap an analytical function in another function?

This is with Hive 0.11.

Best Solution

Not sure this is the root of your problem, but seems like your query is missing an AS keyword (note the all-caps AS on line 8 below).

select 
    case 
        when ta_end_datetime_berekenen = 'Y' 
    then 
        lead(ta_update_datetime) over ( partition by dn_waarde_van, dn_waarde_tot order by ta_update_datetime ) 
    else 
        ea_end_datetime 
    end AS ea_end_datetime, 
    ta_insert_datetime, 
    ta_update_datetime 
from tmp_wtdh_bestedingsklasse_10_s2_stap2
Related Question