deniskuzZ commented on code in PR #4998:
URL: https://github.com/apache/hive/pull/4998#discussion_r1555760730


##########
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/FilterStringColLikeStringScalar.java:
##########
@@ -140,4 +108,100 @@ public Checker tryCreate(String pattern) {
       return new ComplexChecker("^" + UDFLike.likePatternToRegExp(pattern) + 
"$");
     }
   }
+
+  private enum UDFLikePattern {
+    BEGIN(BeginChecker.class, UDFLike.PatternType.BEGIN),
+    END(EndChecker.class, UDFLike.PatternType.END),
+    MIDDLE(MiddleChecker.class, UDFLike.PatternType.MIDDLE),
+    NONE(NoneChecker.class, UDFLike.PatternType.NONE),
+    CHAINED(ChainedChecker.class, UDFLike.PatternType.CHAINED);
+
+    Class<? extends Checker> checker;
+    UDFLike.PatternType type;
+
+    UDFLikePattern(Class<? extends Checker> checker, UDFLike.PatternType type) 
{
+      this.checker = checker;
+      this.type = type;
+    }
+
+    public Checker apply(String pattern) {
+      String matche = check(pattern);
+      if (matche != null) {
+        try {
+          return checker.getConstructor(String.class).newInstance(matche);
+        } catch (Exception e) {
+          throw new IllegalArgumentException("unable to initialize Checker");
+        }
+      }
+
+      return null;
+    }
+
+    private String check(String pattern) {
+      UDFLike.PatternType lastType = UDFLike.PatternType.NONE;
+      int length = pattern.length();
+      int beginIndex = 0;
+      int endIndex = length;
+      char lastChar = 0;
+      StringBuilder strPattern = new StringBuilder();
+      String simplePattern;
+
+      for (int i = 0; i < length; i++) {
+        char n = pattern.charAt(i);
+        if (n == '_') { // such as "a_b"
+          if (lastChar != '\\') { // such as "a%bc"
+            return null;
+          } else { // such as "abc\%de%"

Review Comment:
   `abc\_de%` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to