Hisoka-X commented on code in PR #5768:
URL: https://github.com/apache/seatunnel/pull/5768#discussion_r1389156175


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLFilter.java:
##########
@@ -162,11 +170,29 @@ private boolean likeExpr(LikeExpression likeExpression, 
Object[] inputFields) {
         }
         Expression rightExpr = likeExpression.getRightExpression();
         Object rightVal = zetaSQLFunction.computeForValue(rightExpr, 
inputFields);
-        if (rightVal == null) {
+        String regex = rightVal.toString();
+        if (rightVal == null && regex.length() > 0) {
             return false;
         }
-
-        String regex = rightVal.toString().replace("%", ".*").replace("_", 
".");
+        String likeIdent = "%";
+        if (regex.startsWith(likeIdent)) {
+            regex = regex.replaceFirst(likeIdent, ".*");
+        }
+        if (regex.endsWith(likeIdent)) {
+            regex = regex.substring(0, regex.length() - 1) + ".*";
+        }
+        if (regex.startsWith("_")) {
+            regex = regex.replaceFirst("_", ".");
+        }
+        if (regex.endsWith("_")) {
+            regex = regex.substring(0, regex.length() - 1) + ".";
+        }
+        if (regex.length() >= 3 && regex.substring(regex.length() - 
3).endsWith("_.*")) {
+            regex = regex.substring(0, regex.length() - 3) + "..*";
+        }
+        if (regex.startsWith("'") && regex.endsWith("'")) {
+            regex = regex.substring(0, regex.length() - 1).substring(1);
+        }
         if (regex.startsWith("'") && regex.endsWith("'")) {
             regex = regex.substring(0, regex.length() - 1).substring(1);
         }

Review Comment:
   Why this logic exist twice?



-- 
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]

Reply via email to