924060929 commented on code in PR #49416: URL: https://github.com/apache/doris/pull/49416#discussion_r2013301879
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java: ########## @@ -261,8 +261,14 @@ protected Expression uncheckedCastTo(DataType targetType) throws AnalysisExcepti return new CharLiteral(desc, ((CharType) targetType).getLen()); } } else if (targetType.isVarcharType()) { + if (this.dataType.isDoubleType() || this.dataType.isFloatType()) { + return new VarcharLiteral(desc.replaceAll("\\.0+$", ""), ((VarcharType) targetType).getLen()); + } return new VarcharLiteral(desc, ((VarcharType) targetType).getLen()); } else if (targetType instanceof StringType) { + if (this.dataType.isDoubleType() || this.dataType.isFloatType()) { + return new StringLiteral(desc.replaceAll("\\.0+$", "")); + } Review Comment: please don't use replace regex because of low performance. I think you should optimize the code like this: ```java private static int findPointZeroIndex(String str) { int pointIndex = -1; for (int i = 0; i < str.length(); ++i) { char c = str.charAt(i); if (pointIndex > 0 && c != '0') { return -1; } else if (pointIndex == -1 && c == '.') { pointIndex = i; } } return pointIndex; } int pointZeroIndex = findPointZeroIndex(desc); if (pointZeroIndex > -1) { return new VarcharLiteral(desc.substring(0, pointZeroIndex), ((VarcharType) targetType).getLen()); } else { return new VarcharLiteral(desc, ((VarcharType) targetType).getLen()); } ``` -- 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