-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix](Nereids) fix double literal to string literal cast problem #49416
Conversation
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
Outdated
Show resolved
Hide resolved
...ssion-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy
Outdated
Show resolved
Hide resolved
run buildall |
TPC-H: Total hot run time: 34064 ms
|
TPC-DS: Total hot run time: 193493 ms
|
ClickBench: Total hot run time: 31.1 s
|
...ssion-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
Show resolved
Hide resolved
run buildall |
...ssion-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy
Outdated
Show resolved
Hide resolved
...ssion-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
Show resolved
Hide resolved
TPC-H: Total hot run time: 35135 ms
|
TPC-DS: Total hot run time: 186698 ms
|
ClickBench: Total hot run time: 30.87 s
|
run buildall |
TPC-H: Total hot run time: 33868 ms
|
TPC-DS: Total hot run time: 193312 ms
|
ClickBench: Total hot run time: 31.51 s
|
PR approved by at least one committer and no changes requested. |
PR approved by anyone and no changes requested. |
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+$", "")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't use replace regex because of low performance.
I think you should optimize the code like this:
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());
}
does backend have different behavior to your fix? @LiBinfeng-01 for example: set debug_skip_fold_constant=true;
select cast(1.00000 as varchar(4)); the backend return the result but your fix will replace |
fe and be have same behavior:
|
run buildall |
TPC-H: Total hot run time: 34278 ms
|
TPC-DS: Total hot run time: 193467 ms
|
ClickBench: Total hot run time: 30.96 s
|
PR approved by at least one committer and no changes requested. |
…problem #49416 (#49522) Cherry-picked from #49416 Co-authored-by: LiBinfeng <[email protected]>
…problem #49416 (#49523) Cherry-picked from #49416 Co-authored-by: LiBinfeng <[email protected]>
What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
Release note
When cast double like 1.000 to string, it should strip .000 in the trailing of double
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)