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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM