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

 

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

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

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

impala执行结果为:  helloworld

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

 

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里面执行hive脚本 函数nvl2()与replace()报错

 

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

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

beeline执行结果为: helloworld

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

 

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里面执行hive脚本 函数nvl2()与replace()报错

 

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里面执行hive脚本 函数nvl2()与replace()报错

 

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

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

beeline执行结果: DUAN FEIXIA

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

 

相关文章:

  • 2022-02-02
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
  • 2021-12-16
  • 2022-01-21
  • 2021-12-04
相关资源
相似解决方案