zoukankan      html  css  js  c++  java
  • Beeline里面执行hive脚本 函数nvl2()与replace()报错

    Beeline里面执行hive脚本函数nvl2()与replace()报错

    写脚本的时候是在impala里面执行的,都正常,但是转换为调度的时候是在beeline里面执行的 就会有问题了. 详情如下:

    replace函数: (去掉字符串里面所有空格)

    select replace(' hell o wor d ',' ','');

    impala执行命令: select replace(' hell o wor d ',' ',''); 

    impala执行结果为:  helloworld

     

    beeline执行命令: select replace(' hell o wor d ',' ','');

    beeline执行结果为:Error: Error while compiling statement: FAILED: SemanticException Line 0:-1 Invalid function 'replace' (state=42000,code=40000)

     

    beeline解决方案: 使用 translate函数替换replace函数

    beeline执行命令: select translate(' hell o wor d ',' ','');

    beeline执行结果为: helloworld

     

     

    nvl2()函数: 判断第一个表达式是否为空,如果为空则取第三表达式的值,如果不为空则取第二个表达式的值

    select nvl2('FEIXIA',concat(translate('DU AN',' ',''),' ',translate('FEI XIA ',' ','')),NULL);

    impala执行命令: select nvl2('FEIXIA',concat(translate('DU AN',' ',''),' ',translate('FEI XIA ',' ','')),NULL);

    impala执行结果: DUAN FEIXIA

     

    beeline执行命令: select nvl2('FEIXIA',concat(translate('DU AN',' ',''),' ',translate('FEI XIA ',' ','')),NULL);

    beeline执行结果:  Error: Error while compiling statement: FAILED: SemanticException [Error 10011]: Line 1:7 Invalid function 'nvl2' (state=42000,code=10011)

     

    beeline解决方案: 使用case when 处理

    beeline执行命令: select case when nvl('FEIXIA','')<>'' then concat(translate('DU AN',' ',''),' ',translate('FEI XIA ',' ','')) else '' end englishName;

    beeline执行结果: DUAN FEIXIA

  • 相关阅读:
    Longest Palindromic Substring问题
    twosum问题
    longest substring问题
    特殊的ARP
    【转】人肉搜索技巧
    ARP攻击
    Linux kali安装及常用命令收集
    【转】ICMP协议
    SpringBoot集成Mybatis-XML方式通用Mapper
    springMVC的controller中insert()多次,记优惠券被多次领取
  • 原文地址:https://www.cnblogs.com/DFX339/p/11660077.html
Copyright © 2011-2022 走看看