hive like与rlike的区别

2022-09-17 14:47:45 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

项目github地址:[bitcarmanlee easy-algorithm-interview-and-practice](https://github.com/bitcarmanlee/easy-algorithm-interview-and-practice) 欢迎大家star,留言,一起学习进步

like与rlike的区别: like不是正则,而是通配符。这个通配符可以看一下SQL的标准,例如%代表任意多个字符。 rlike是正则,正则的写法与java一样。’’需要使用’\’,例如’w’需要使用’\w’

hive> select “aaaaa” like “�a%” from test_struct limit 10; Total jobs = 1 … OK true true Time taken: 22.056 seconds, Fetched: 2 row(s)

hive> select “aaaaa” rlike “�a%” from test_struct limit 10; Total jobs = 1 … OK false false Time taken: 26.065 seconds, Fetched: 2 row(s)

注意这两者区别:%是sql中的通配符,所以用like的输出为true。而正则里没有%的表示方式,所以输出false rlike的话,用相应的正则表达式即可

hive> select “aaaaa” rlike “.*aaa.*” from test_struct limit 10; Total jobs = 1 … OK true true Time taken: 24.168 seconds, Fetched: 2 row(s)

select “aaaaa” rlike “^aaa” from test_struct limit 10; Total jobs = 1 … OK true true Time taken: 22.059 seconds, Fetched: 2 row(s)

hive> select “aaa” rlike “aa\w” from test_struct limit 2; Total jobs = 1 Launching Job 1 out of 1 … OK true true Time taken: 22.055 seconds, Fetched: 2 row(s)

hive> select “aaa” rlike “aa\w ” from test_struct limit 2; Total jobs = 1 Launching Job 1 out of 1 … OK true true Time taken: 22.055 seconds, Fetched: 2 row(s)

以上几种方式的正则都可以

rp_name_cn like ‘%不含早%’ 与rp_name_cn rlike ‘不含早’的效果一致

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/158799.html原文链接:https://javaforall.cn

0 人点赞