maytasm commented on code in PR #18281:
URL: https://github.com/apache/druid/pull/18281#discussion_r2229471077


##########
processing/src/main/java/org/apache/druid/query/expression/RegexpLikeExprMacro.java:
##########
@@ -45,49 +45,92 @@ public String name()
   public Expr apply(final List<Expr> args)
   {
     validationHelperCheckArgumentCount(args, 2);
+    if (ExprUtils.isStringLiteral(args.get(1))) {
+      return new RegexpLikeExpr(args);
+    } else {
+      return new RegexpLikeDynamicExpr(args);
+    }
+  }
 
-    final Expr arg = args.get(0);
-    final Expr patternExpr = args.get(1);
+  abstract class BaseRegexpLikeExpr extends 
ExprMacroTable.BaseScalarMacroFunctionExpr
+  {
+    public BaseRegexpLikeExpr(final List<Expr> args)
+    {
+      super(RegexpLikeExprMacro.this, args);
+    }
 
-    if (!ExprUtils.isStringLiteral(patternExpr)) {
-      throw validationFailed("pattern must be a STRING literal");
+    @Nullable
+    @Override
+    public ExpressionType getOutputType(InputBindingInspector inspector)
+    {
+      return ExpressionType.LONG;
     }
+  }
 
-    // Precompile the pattern.
-    final Pattern pattern = Pattern.compile(
-        StringUtils.nullToEmptyNonDruidDataString((String) 
patternExpr.getLiteralValue())
-    );
+  /**
+   * Expr when pattern is a literal.
+   */
+  class RegexpLikeExpr extends BaseRegexpLikeExpr
+  {
+    private final Expr arg;
+    private final Pattern pattern;
 
-    class RegexpLikeExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
+    private RegexpLikeExpr(List<Expr> args)
     {
-      private RegexpLikeExpr(List<Expr> args)
-      {
-        super(RegexpLikeExprMacro.this, args);
-      }
+      super(args);
 
-      @Nonnull
-      @Override
-      public ExprEval eval(final ObjectBinding bindings)
-      {
-        final String s = arg.eval(bindings).asString();
-
-        if (s == null) {
-          // True nulls do not match anything. Note: this branch only executes 
in SQL-compatible null handling mode.
-          return ExprEval.ofLong(null);
-        } else {
-          final Matcher matcher = pattern.matcher(s);
-          return ExprEval.ofLongBoolean(matcher.find());
-        }
+      final Expr patternExpr = args.get(1);
+      if (patternExpr.getLiteralValue() == null) {

Review Comment:
   nit: use ExprUtils.isStringLiteral() method



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