简体   繁体   中英

Hadoop SQL - Impala and a calculated field

I am very new to Hadoop and attempting to use a "calculated" field as one would in SQL:

SELECT "one" as test, 
    CASE WHEN calculated test = "one" then "This works"
    else "Nope" 
    end as checker

But it appears this generates an error:

AnalysisException: Syntax error in line 1: ...est, CASE WHEN calculated test = "one" then "This work... ^ Encountered: IDENTIFIER Expected: AND, BETWEEN, DIV, ILIKE, IN, IREGEXP, IS, LIKE, NOT, OR, REGEXP, RLIKE, THEN CAUSED BY: Exception: Syntax error

Is it not possible to use a "calculated" field in Hadoop? If so, what am I doing wrong? Apologies if I am missing something obvious, again, new to Hadoop.

It is not. calculated is not a reserve word for Impala SQL.

You should probably use if or case instead.

Here are some examples, from the article Impala Conditional Functions: IF, CASE, COALESCE, DECODE, NVL, ZEROIFNULL :

 select if(1=1,'TRUE','FALSE') as IF_TEST; 

...

 select case x when 1 then 'one' when 2 then 'two' when 0 then 'zero' else 'out of range' end from t1; 

References:

The below query may work the way you want in hive/impala

select 
    case when test="one" then "this works"
    else "nope" end as checker 
    from 
    (select "one" as test) a;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM