关于hive中not like的语法错误

hive的低版本中不支持not like的语法,在执行类似如下语句时会报错

create table ljp as
select gmt_created, first_user_name, servicer_name
from bds_c04_s_ocs_sessions
where first_user_name not like ‘游客%’;

错误信息如下:

FAILED: Parse Error: line 16:4 cannot recognize input near ‘first_user_name’ ‘not’ ‘like’ in expression specification

解决方案有两种:
一、修改语句,将not放在表达式前面,即改为这样:not (a like ‘B%’)
二、或升级hive版本,如在hive 1.1.7版本中,即可兼容not like语法。其他如not in等语句,也类似。详见社区的issue:https://issues.apache.org/jira/browse/HIVE-1740

END


Data Warehouse For Ever原创文章,转载请注明出处

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>