This is an automated email from the ASF dual-hosted git repository.
englefly pushed a commit to branch branch-3.0.3
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0.3 by this push:
new 2efdc82750d branch-3.0 [fix](nerieds)removing tailing .0 from
DoubleLiteral.getStringValue() (#51679)
2efdc82750d is described below
commit 2efdc82750df31c8625d6311c6233998300a6100
Author: minghong <[email protected]>
AuthorDate: Sun Jun 22 07:48:28 2025 +0800
branch-3.0 [fix](nerieds)removing tailing .0 from
DoubleLiteral.getStringValue() (#51679)
### What problem does this PR solve?
pick#51679
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
---
.../trees/expressions/literal/DoubleLiteral.java | 30 ++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteral.java
index bc7b356c376..a18f2e377bb 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteral.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteral.java
@@ -49,4 +49,34 @@ public class DoubleLiteral extends FractionalLiteral {
public LiteralExpr toLegacyLiteral() {
return new FloatLiteral(value, Type.DOUBLE);
}
+
+ @Override
+ public String getStringValue() {
+ Double num = getValue();
+ if (Double.isNaN(num)) {
+ return "nan";
+ } else if (Double.isInfinite(num)) {
+ return num > 0 ? "inf" : "-inf";
+ }
+
+ // Use %.17g to format the result,replace 'E' with 'e'
+ String formatted = String.format("%.17g", num).replace('E', 'e');
+
+ // Remove trailing .0 in scientific notation.
+ if (formatted.contains("e")) {
+ String[] parts = formatted.split("e");
+ String mantissa = parts[0];
+ String exponent = parts.length > 1 ? "e" + parts[1] : "";
+ mantissa = mantissa.replaceAll("\\.?0+$", "");
+ if (mantissa.isEmpty()) {
+ mantissa = "0";
+ }
+ formatted = mantissa + exponent;
+ } else if (formatted.contains(".")) {
+ // remove trailing .0 in fixed-point representation
+ formatted = formatted.replaceAll("\\.?0+$", "");
+ }
+
+ return formatted;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]