You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "leung-ming (via GitHub)" <gi...@apache.org> on 2025/06/19 19:13:51 UTC
[PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
leung-ming opened a new pull request, #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
The `continue` after `append_null` was forgotten
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
Add `continue`
## How are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
org.apache.comet.CometCastSuite
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "leung-ming (via GitHub)" <gi...@apache.org>.
leung-ming commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2164577355
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
> I personally think that having an `else` condition makes the code easier to comprehend than using `continue`.
Agree.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#issuecomment-2997096994
The CI test failure is unrelated to changes in this PR and is now fixed in main branch
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#issuecomment-2992205661
Would you like to add a unit test to cover this case?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#issuecomment-2997064670
Thanks @leung-ming, for the test on the native side. I was really thinking of a unit test in `org.apache.comet.CometCastSuite`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2162048955
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
I am surprised that no existing tests caught this issue :confused:. As @parthchandra said, it would be good to have a test in `CometCastSuite` to expose this bug.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "leung-ming (via GitHub)" <gi...@apache.org>.
leung-ming commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2163128943
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
> Thanks for catching the bug @leung-ming - the code can currently append both a null and a value, which is incorrect.
>
> However, using `continue` does not seem to be the correct fix because if will terminate the `for` loop and stop processing the remaining data in the vector.
>
> I think we just need an `else` condition instead:
>
> ```rust
> if Decimal128Type::validate_decimal_precision(v, precision).is_err() {
> if eval_mode == EvalMode::Ansi {
> return Err(SparkError::NumericValueOutOfRange {
> value: input_value.to_string(),
> precision,
> scale,
> });
> } else {
> cast_array.append_null();
> }
> } else {
> cast_array.append_value(v);
> }
> ```
Sorry, I really don't understand, I am new to Rust. Your words make sense to me if there is a `break` instead of `continue`.
If you mean code quality/style, how about the follow one:
```rust
for i in 0..input.len() {
if input.is_null(i) {
cast_array.append_null();
continue;
}
let input_value = input.value(i).as_();
if let Some(v) = (input_value * mul).round().to_i128() {
if Decimal128Type::validate_decimal_precision(v, precision).is_ok() {
cast_array.append_value(v);
continue;
}
};
if eval_mode == EvalMode::Ansi {
return Err(SparkError::NumericValueOutOfRange {
value: input_value.to_string(),
precision,
scale,
});
}
cast_array.append_null();
}
```
I think all three should do the same things.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2164336592
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
I personally think that having an `else` condition makes the code easier to comprehend than using `continue`.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2162047684
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
Thanks for catching the bug @leung-ming - the code can currently append both a null and a value, which is incorrect.
However, using `continue` does not seem to be the correct fix because if will terminate the `for` loop and stop processing the remaining data in the vector.
I think we just need an `else` condition instead:
```rust
if Decimal128Type::validate_decimal_precision(v, precision).is_err() {
if eval_mode == EvalMode::Ansi {
return Err(SparkError::NumericValueOutOfRange {
value: input_value.to_string(),
precision,
scale,
});
} else {
cast_array.append_null();
}
} else {
cast_array.append_value(v);
}
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "leung-ming (via GitHub)" <gi...@apache.org>.
leung-ming commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2163222203
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
> I am surprised that no existing tests caught this issue 😕. As @parthchandra said, it would be good to have a test in `CometCastSuite` to expose this bug.
Maybe hidden by #1372? I found this issue when I testing #1915 (which marked the cast as compatible) with existing tests.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "leung-ming (via GitHub)" <gi...@apache.org>.
leung-ming commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2163222203
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
> I am surprised that no existing tests caught this issue 😕. As @parthchandra said, it would be good to have a test in `CometCastSuite` to expose this bug.
Maybe hidden by #1372? I found this issue when I testing #1915 (which marked the cast compatible) with existing tests.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "leung-ming (via GitHub)" <gi...@apache.org>.
leung-ming commented on PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#issuecomment-2992275004
> Would you like to add a unit test to cover this case?
Ok, do it later.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "leung-ming (via GitHub)" <gi...@apache.org>.
leung-ming commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2163222203
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
> I am surprised that no existing tests caught this issue 😕. As @parthchandra said, it would be good to have a test in `CometCastSuite` to expose this bug.
Maybe hidden by #1372? I found this issue when I testing #1915 (which marked the cast compatible) with existing test.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#issuecomment-3001116353
The CI failure can be fixed by merging latest from main branch.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#issuecomment-2990050268
## [Codecov](https://app.codecov.io/gh/apache/datafusion-comet/pull/1914?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 32.93%. Comparing base [(`f09f8af`)](https://app.codecov.io/gh/apache/datafusion-comet/commit/f09f8af64c6599255e116a376f4f008f2fd63b43?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`9a5eb69`)](https://app.codecov.io/gh/apache/datafusion-comet/commit/9a5eb691b789783528ccdb32520d7fd8bc79ab96?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
> Report is 272 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #1914 +/- ##
=============================================
- Coverage 56.12% 32.93% -23.20%
+ Complexity 976 800 -176
=============================================
Files 119 130 +11
Lines 11743 12746 +1003
Branches 2251 2405 +154
=============================================
- Hits 6591 4198 -2393
- Misses 4012 7576 +3564
+ Partials 1140 972 -168
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/datafusion-comet/pull/1914?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2164334275
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
> Sorry, I really don't understand, I am new to Rust. Your words make sense to me if there is a `break` instead of `continue`.
You are correct. I misinterpreted this.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2164429663
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
> If you mean code quality/style, how about the follow one:
>
> ```rust
> for i in 0..input.len() {
> if input.is_null(i) {
> cast_array.append_null();
> continue;
> }
>
> let input_value = input.value(i).as_();
> if let Some(v) = (input_value * mul).round().to_i128() {
> if Decimal128Type::validate_decimal_precision(v, precision).is_ok() {
> cast_array.append_value(v);
> continue;
> }
> };
>
> if eval_mode == EvalMode::Ansi {
> return Err(SparkError::NumericValueOutOfRange {
> value: input_value.to_string(),
> precision,
> scale,
> });
> }
> cast_array.append_null();
> }
> ```
Yes, this is easier to follow.
You could call `is_validate_decimal_precision` rather than checking for a Result on `validate_decimal_precision` and it should be more efficient.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Add continue after append_null when casting float to decimal [datafusion-comet]
Posted by "leung-ming (via GitHub)" <gi...@apache.org>.
leung-ming commented on code in PR #1914:
URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2164577686
##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -1298,6 +1298,7 @@ where
});
} else {
cast_array.append_null();
+ continue;
Review Comment:
> > If you mean code quality/style, how about the follow one:
> > ```rust
> > for i in 0..input.len() {
> > if input.is_null(i) {
> > cast_array.append_null();
> > continue;
> > }
> >
> > let input_value = input.value(i).as_();
> > if let Some(v) = (input_value * mul).round().to_i128() {
> > if Decimal128Type::validate_decimal_precision(v, precision).is_ok() {
> > cast_array.append_value(v);
> > continue;
> > }
> > };
> >
> > if eval_mode == EvalMode::Ansi {
> > return Err(SparkError::NumericValueOutOfRange {
> > value: input_value.to_string(),
> > precision,
> > scale,
> > });
> > }
> > cast_array.append_null();
> > }
> > ```
>
> Yes, this is easier to follow.
>
> You could call `is_validate_decimal_precision` rather than checking for a Result on `validate_decimal_precision` and it should be more efficient.
Yes, thanks!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org