FAQ
Author: kevinwilfong
Date: Tue Mar 13 01:45:58 2012
New Revision: 1299948

URL: http://svn.apache.org/viewvc?rev=1299948&view=rev
Log:
HIVE-2714. Lots of special characters are not handled in LIKE. (jonchang via kevinwilfong)

Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLike.java
hive/trunk/ql/src/test/queries/clientpositive/udf_like.q
hive/trunk/ql/src/test/results/clientpositive/udf_like.q.out

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLike.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLike.java?rev=1299948&r1=1299947&r2=1299948&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLike.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLike.java Tue Mar 13 01:45:58 2012
@@ -75,10 +75,7 @@ public class UDFLike extends UDF {
} else if (n == '%') {
sb.append(".*");
} else {
- if ("\\[](){}.*^$".indexOf(n) != -1) {
- sb.append('\\');
- }
- sb.append(n);
+ sb.append(Pattern.quote(Character.toString(n)));
}
}
return sb.toString();
@@ -91,16 +88,16 @@ public class UDFLike extends UDF {
* string in it for later pattern matching if it is a simple pattern.
* <p>
* Examples: <blockquote>
- *
+ *
* <pre>
* parseSimplePattern("%abc%") changes {@link #type} to PatternType.MIDDLE
* and changes {@link #simplePattern} to "abc"
* parseSimplePattern("%ab_c%") changes {@link #type} to PatternType.COMPLEX
* and does not change {@link #simplePattern}
* </pre>
- *
+ *
* </blockquote>
- *
+ *
* @param likePattern
* the input LIKE query pattern
*/

Modified: hive/trunk/ql/src/test/queries/clientpositive/udf_like.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_like.q?rev=1299948&r1=1299947&r2=1299948&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_like.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_like.q Tue Mar 13 01:45:58 2012
@@ -11,3 +11,11 @@ SELECT '_%_' LIKE '%\_\%\_%', '__' LIKE
'_%_' LIKE '\%\_%', '%__' LIKE '__\%%', '_%' LIKE '\_\%\_\%%', '_%' LIKE '\_\%_%',
'%_' LIKE '\%\_', 'ab' LIKE '\%\_', 'ab' LIKE '_a%', 'ab' LIKE 'a','ab' LIKE '','' LIKE ''
FROM src WHERE src.key = 86;
+
+
+SELECT '1+2' LIKE '_+_',
+ '1+2' LIKE '1+_',
+ '112' LIKE '1+_',
+ '|||' LIKE '|_|',
+ '+++' LIKE '1+_'
+FROM src LIMIT 1;

Modified: hive/trunk/ql/src/test/results/clientpositive/udf_like.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_like.q.out?rev=1299948&r1=1299947&r2=1299948&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_like.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_like.q.out Tue Mar 13 01:45:58 2012
@@ -99,3 +99,22 @@ POSTHOOK: type: QUERY
POSTHOOK: Input: default@src
#### A masked pattern was here ####
true false true true false false false false true false false false false true
+PREHOOK: query: SELECT '1+2' LIKE '_+_',
+ '1+2' LIKE '1+_',
+ '112' LIKE '1+_',
+ '|||' LIKE '|_|',
+ '+++' LIKE '1+_'
+FROM src LIMIT 1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT '1+2' LIKE '_+_',
+ '1+2' LIKE '1+_',
+ '112' LIKE '1+_',
+ '|||' LIKE '|_|',
+ '+++' LIKE '1+_'
+FROM src LIMIT 1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+true true false true false

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupcommits @
categorieshive, hadoop
postedMar 13, '12 at 1:46a
activeMar 13, '12 at 1:46a
posts1
users1
websitehive.apache.org

1 user in discussion

Kevinwilfong: 1 post

People

Translate

site design / logo © 2021 Grokbase