julianhyde commented on code in PR #4460:
URL: https://github.com/apache/calcite/pull/4460#discussion_r2191769288


##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -511,6 +512,15 @@ private RexNode simplifyLike(RexCall e, RexUnknownAs 
unknownAs) {
     return simplifyGenericNode(e);
   }
 
+  private boolean withSameChar(String str, Character c) {
+    for (Character character : str.toCharArray()) {

Review Comment:
   It's still too complicated. Does this work?
   ```
   diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java 
b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
   index 4710bb1f2..0ac82fb75 100644
   --- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
   +++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
   @@ -500,13 +500,22 @@ private RexNode simplifyDivide(RexCall e) {
      private RexNode simplifyLike(RexCall e, RexUnknownAs unknownAs) {
        if (e.operands.get(1) instanceof RexLiteral) {
          final RexLiteral literal = (RexLiteral) e.operands.get(1);
   -      if ("%".equals(literal.getValueAs(String.class))) {
   +      String pattern = requireNonNull(literal.getValueAs(String.class));
   +      String pattern2 = pattern.replaceAll("%+", "%");
   +      if ("%".equals(pattern2)) {
            // "x LIKE '%'" simplifies to "x = x"
            final RexNode x = e.operands.get(0);
            return simplify(
                rexBuilder.makeCall(
                    e.getParserPosition(), SqlStdOperatorTable.EQUALS, x, x), 
unknownAs);
          }
   +      if (!pattern2.equals(pattern)) {
   +        // Simplify "x LIKE '%%a%%%'" to "x LIKE '%a%'"
   +        final RexNode x = e.operands.get(0);
   +        final RexNode x2 = simplify(x, unknownAs);
   +        return rexBuilder.makeCall(e.getParserPosition(),
   +            SqlStdOperatorTable.LIKE, x2, rexBuilder.makeLiteral(pattern2));
   +      }
        }
        return simplifyGenericNode(e);
      }
   ```
   



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