Skip to content

[function](cast)Make string casting to integers more like MySQL's beh… - #41541

Merged
yiguolei merged 2 commits into
apache:branch-2.1from
Mryange:branch-2.1-pick-38847
Oct 11, 2024
Merged

[function](cast)Make string casting to integers more like MySQL's beh…#41541
yiguolei merged 2 commits into
apache:branch-2.1from
Mryange:branch-2.1-pick-38847

Conversation

@Mryange

Copy link
Copy Markdown
Contributor

…avior (#38847)
#38847

Proposed changes

There are two issues here. First, the results of casting are inconsistent between FE and BE .

FE
mysql [(none)]>select cast('3.000' as int); +----------------------+
| cast('3.000' as INT) |
+----------------------+
| 3 |
+----------------------+
mysql [(none)]>set debug_skip_fold_constant = true;
BE
mysql [(none)]>select cast('3.000' as int);
+----------------------+
| cast('3.000' as INT) |
+----------------------+
| NULL |
+----------------------+

The second issue is that casting on BE converts '3.0' to null. Here, the casting logic for FE and BE has been unified

Proposed changes

Issue Number: close #xxx

…avior (apache#38847)
## Proposed changes
There are two issues here. First, the results of casting are
inconsistent between FE and BE .
```
FE
mysql [(none)]>select cast('3.000' as int); +----------------------+
| cast('3.000' as INT) |
+----------------------+
| 3 |
+----------------------+
mysql [(none)]>set debug_skip_fold_constant = true;
BE
mysql [(none)]>select cast('3.000' as int);
+----------------------+
| cast('3.000' as INT) |
+----------------------+
| NULL |
+----------------------+
```
The second issue is that casting on BE converts '3.0' to null. Here, the
casting logic for FE and BE has been unified
<!--Describe your changes.-->
@doris-robot

Copy link
Copy Markdown

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

@Mryange

Copy link
Copy Markdown
ContributorAuthor

run buildall

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment threadbe/src/util/string_parser.hpp
Comment threadbe/src/util/string_parser.hpp
Comment threadbe/src/util/string_parser.hpp
@Mryange

Copy link
Copy Markdown
ContributorAuthor

run beut

@Mryange
Mryangeforce-pushed the branch-2.1-pick-38847 branch from 4c337aa to cb9d8baCompareOctober 8, 2024 12:42
@Mryange

Copy link
Copy Markdown
ContributorAuthor

run buildall

@doris-robot

Copy link
Copy Markdown

TeamCity be ut coverage result:
Function Coverage: 36.10% (9342/25876)
Line Coverage: 27.67% (76740/277346)
Region Coverage: 26.46% (39405/148896)
Branch Coverage: 23.24% (20047/86246)
Coverage Report: http://coverage.selectdb-in.cc/coverage/cb9d8ba9b1398d5ecbe112571a695d838caf791e_cb9d8ba9b1398d5ecbe112571a695d838caf791e/report/index.html

@Mryange

Copy link
Copy Markdown
ContributorAuthor

run buildall

@doris-robot

Copy link
Copy Markdown

TeamCity be ut coverage result:
Function Coverage: 36.09% (9339/25876)
Line Coverage: 27.65% (76686/277349)
Region Coverage: 26.45% (39384/148901)
Branch Coverage: 23.24% (20044/86250)
Coverage Report: http://coverage.selectdb-in.cc/coverage/cb9d8ba9b1398d5ecbe112571a695d838caf791e_cb9d8ba9b1398d5ecbe112571a695d838caf791e/report/index.html

@Mryange

Copy link
Copy Markdown
ContributorAuthor

run p0

val = val * 10 + digit;
} else {
if ((UNLIKELY(i == first || !is_all_whitespace(s + i, len - i)))) {
if ((UNLIKELY(i == first || (!is_all_whitespace(s + i, len - i) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前的代码对于 “3 ” 能转为3
这里好像对 “3.1 ” 就不能转为3了

@yiguolei
yiguolei merged commit 6dddd4c into apache:branch-2.1Oct 11, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@Mryange@doris-robot@yiguolei@xinyiZzz