924060929 commented on code in PR #46482:
URL: https://github.com/apache/doris/pull/46482#discussion_r1916043589


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/StringLikeLiteral.java:
##########
@@ -62,6 +66,59 @@ public String getValue() {
         return value;
     }
 
+    @Override
+    public LiteralExpr toLegacyLiteral() {
+        return new org.apache.doris.analysis.StringLiteral(value);
+    }
+
+    @Override
+    public int compareTo(ComparableLiteral other) {
+        if (other instanceof StringLikeLiteral) {
+            // compare string with utf-8 byte array, same with 
DM,BE,StorageEngine
+            byte[] thisBytes = null;
+            byte[] otherBytes = null;
+            try {
+                thisBytes = getStringValue().getBytes("UTF-8");
+                otherBytes = ((Literal) 
other).getStringValue().getBytes("UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                Preconditions.checkState(false);

Review Comment:
   do not eat the exception. new AnalysisException and wrap 
UnsupportedEncodingException and then throw it



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java:
##########
@@ -266,7 +267,13 @@ public Expression visitEqualTo(EqualTo equalTo, 
ExpressionRewriteContext context
         if (checkedExpr.isPresent()) {
             return checkedExpr.get();
         }
-        return BooleanLiteral.of(((Literal) 
equalTo.left()).compareTo((Literal) equalTo.right()) == 0);
+        try {
+            return BooleanLiteral.of(((ComparableLiteral) equalTo.left())
+                    .compareTo((ComparableLiteral) equalTo.right()) == 0);
+        } catch (Exception e) {
+            // left and right maybe not comparable
+            return BooleanLiteral.of(equalTo.left().equals(equalTo.right()));
+        }

Review Comment:
   add this to try best to avoid throw exception because throw exception are 
too slow, similar modifications also need to be made in this way
   ```java
   if (equalTo.left() instanceof ComparableLiteral && equalsTo.right() 
instanceof ComparableLiteral) {
       try {
           return BooleanLiteral.of(((ComparableLiteral) equalTo.left())
                           .compareTo((ComparableLiteral) equalTo.right()) == 
0);
       } catch (Exception e) {
           return BooleanLiteral.of(equalTo.left().equals(equalTo.right()));
       }
   } else {
      return BooleanLiteral.of(equalTo.left().equals(equalTo.right()));
   }
   ```



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to