impala和一个计算字段

uplii1fm  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(415)

我对hadoop非常陌生,尝试像在sql中那样使用“计算”字段:

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

但这似乎产生了一个错误:
analysisexception:第1行语法错误:…est,case when calculated test=“one”then“this work…”遇到:标识符应为:and、between、div、ilike、in、iregexp、is、like、not、or、regexp、rlike,然后由:exception:语法错误引起
在hadoop中不能使用“计算”字段吗?如果是,我做错了什么?抱歉,如果我错过了一些明显的,再次,新的hadoop。

m4pnthwp

m4pnthwp1#

下面的查询在hive/impala中可能按您所希望的方式工作

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

koaltpgm2#

事实并非如此。 calculated 不是impala sql的保留字。
你应该用 if 或者 case 相反。
以下是文章impala条件函数中的一些示例: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;

参考文献:
Impala 保留字
Impala 条件函数

相关问题