You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/09/02 20:04:01 UTC
[GitHub] [arrow-datafusion] iajoiner opened a new pull request, #3347: Replace `unwrap` in `convert_to_ordered_float`
iajoiner opened a new pull request, #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347
# 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.
-->
Part of #3316.
# 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.
-->
Replace unwraps with Results
# 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.
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] avantgardnerio commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float`
Posted by GitBox <gi...@apache.org>.
avantgardnerio commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r961976592
##########
datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs:
##########
@@ -272,79 +272,129 @@ impl ApproxPercentileAccumulator {
) -> Result<Vec<OrderedFloat<f64>>> {
match values.data_type() {
DataType::Float64 => {
- let array = values.as_any().downcast_ref::<Float64Array>().unwrap();
+ let array = values.as_any().downcast_ref::<Float64Array>().ok_or(
+ DataFusionError::Internal(format!(
+ "A Float64 type array, {:?} is somehow not a Float64Array",
+ values
Review Comment:
I assume this won't print out 1GB of values in binary?
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] iajoiner commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float`
Posted by GitBox <gi...@apache.org>.
iajoiner commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r962006492
##########
datafusion/physical-expr/src/aggregate/approx_percentile_cont.rs:
##########
@@ -272,79 +272,129 @@ impl ApproxPercentileAccumulator {
) -> Result<Vec<OrderedFloat<f64>>> {
match values.data_type() {
DataType::Float64 => {
- let array = values.as_any().downcast_ref::<Float64Array>().unwrap();
+ let array = values.as_any().downcast_ref::<Float64Array>().ok_or(
+ DataFusionError::Internal(format!(
+ "A Float64 type array, {:?} is somehow not a Float64Array",
+ values
Review Comment:
This won't. The following function is usually used when implementing `Debug`.
https://github.com/apache/arrow-rs/blob/master/arrow/src/array/array.rs#L719-L757
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] iajoiner commented on pull request #3347: Replace `unwrap` in `convert_to_ordered_float`
Posted by GitBox <gi...@apache.org>.
iajoiner commented on PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#issuecomment-1235856342
cc @avantgardnerio @andygrove
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] codecov-commenter commented on pull request #3347: Replace `unwrap` in `convert_to_ordered_float`
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#issuecomment-1235875101
# [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/3347?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#3347](https://codecov.io/gh/apache/arrow-datafusion/pull/3347?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0628158) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/24db13ba7532e87f59f7935984c552034580bb7c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (24db13b) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.
```diff
@@ Coverage Diff @@
## master #3347 +/- ##
=======================================
Coverage 85.49% 85.50%
=======================================
Files 294 294
Lines 54060 54072 +12
=======================================
+ Hits 46220 46234 +14
+ Misses 7840 7838 -2
```
| [Impacted Files](https://codecov.io/gh/apache/arrow-datafusion/pull/3347?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...ion/physical-expr/src/aggregate/approx\_distinct.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3347/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1leHByL3NyYy9hZ2dyZWdhdGUvYXBwcm94X2Rpc3RpbmN0LnJz) | `60.46% <100.00%> (+0.94%)` | :arrow_up: |
| [...sical-expr/src/aggregate/approx\_percentile\_cont.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3347/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1leHByL3NyYy9hZ2dyZWdhdGUvYXBwcm94X3BlcmNlbnRpbGVfY29udC5ycw==) | `82.58% <100.00%> (+1.03%)` | :arrow_up: |
| [datafusion/expr/src/logical\_plan/plan.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3347/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy9sb2dpY2FsX3BsYW4vcGxhbi5ycw==) | `78.39% <0.00%> (+0.16%)` | :arrow_up: |
| [datafusion/core/src/physical\_plan/metrics/value.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/3347/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9waHlzaWNhbF9wbGFuL21ldHJpY3MvdmFsdWUucnM=) | `87.43% <0.00%> (+0.50%)` | :arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float` and add `downcast_value`
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r967639082
##########
datafusion/common/src/lib.rs:
##########
@@ -27,3 +27,23 @@ pub use column::Column;
pub use dfschema::{DFField, DFSchema, DFSchemaRef, ExprSchema, ToDFSchema};
pub use error::{field_not_found, DataFusionError, Result, SchemaError};
pub use scalar::{ScalarType, ScalarValue};
+
+#[macro_export]
+macro_rules! downcast_value {
Review Comment:
It would be great to add some doc comments here (especially as this will now become part of the public API). It could be done as a follow on PR too
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float` and add `downcast_value`
Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r967661085
##########
datafusion/common/src/lib.rs:
##########
@@ -27,3 +27,23 @@ pub use column::Column;
pub use dfschema::{DFField, DFSchema, DFSchemaRef, ExprSchema, ToDFSchema};
pub use error::{field_not_found, DataFusionError, Result, SchemaError};
pub use scalar::{ScalarType, ScalarValue};
+
+#[macro_export]
Review Comment:
```suggestion
/// Downcast an Arrow Array to a concrete type, return an `Err` if the cast is
/// not possible.
///
/// Example: `let array = downcast_value!(values, Int32Array)`
#[macro_export]
```
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float` and add `downcast_value`
Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r967661165
##########
datafusion/common/src/lib.rs:
##########
@@ -27,3 +27,23 @@ pub use column::Column;
pub use dfschema::{DFField, DFSchema, DFSchemaRef, ExprSchema, ToDFSchema};
pub use error::{field_not_found, DataFusionError, Result, SchemaError};
pub use scalar::{ScalarType, ScalarValue};
+
+#[macro_export]
+macro_rules! downcast_value {
Review Comment:
I took the liberty of adding some brief docs here
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove merged pull request #3347: Replace `unwrap` in `convert_to_ordered_float` and add `downcast_value`
Posted by GitBox <gi...@apache.org>.
andygrove merged PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float` and add `downcast_value`
Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r967664599
##########
datafusion/common/src/lib.rs:
##########
@@ -27,3 +27,27 @@ pub use column::Column;
pub use dfschema::{DFField, DFSchema, DFSchemaRef, ExprSchema, ToDFSchema};
pub use error::{field_not_found, DataFusionError, Result, SchemaError};
pub use scalar::{ScalarType, ScalarValue};
+
+/// Downcast an Arrow Array to a concrete type, return an `Err` if the cast is
+/// not possible.
+///
Review Comment:
```suggestion
///
```
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float`
Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r962054903
##########
datafusion/physical-expr/src/aggregate/approx_distinct.rs:
##########
@@ -219,7 +219,11 @@ macro_rules! default_accumulator_impl {
() => {
fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
assert_eq!(1, states.len(), "expect only 1 element in the states");
- let binary_array = states[0].as_any().downcast_ref::<BinaryArray>().unwrap();
+ let binary_array = states[0].as_any().downcast_ref::<BinaryArray>().ok_or(
Review Comment:
There is already a macro defined in this file that looks like what we need
```
macro_rules! downcast_value {
($Value: expr, $Type: ident, $T: tt) => {{
$Value[0]
.as_any()
.downcast_ref::<$Type<T>>()
.ok_or_else(|| {
DataFusionError::Internal(format!(
"could not cast value to {}",
type_name::<$Type<T>>()
))
})?
}};
}
```
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float`
Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r962053573
##########
datafusion/physical-expr/src/aggregate/approx_distinct.rs:
##########
@@ -219,7 +219,11 @@ macro_rules! default_accumulator_impl {
() => {
fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
assert_eq!(1, states.len(), "expect only 1 element in the states");
- let binary_array = states[0].as_any().downcast_ref::<BinaryArray>().unwrap();
+ let binary_array = states[0].as_any().downcast_ref::<BinaryArray>().ok_or(
Review Comment:
It might be useful to introduce a helper function or macro for downcasting arrays to expected tyes. I think there might be one in arrow somewhere that I added a long time ago. I will try and find it.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float`
Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r962053573
##########
datafusion/physical-expr/src/aggregate/approx_distinct.rs:
##########
@@ -219,7 +219,11 @@ macro_rules! default_accumulator_impl {
() => {
fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
assert_eq!(1, states.len(), "expect only 1 element in the states");
- let binary_array = states[0].as_any().downcast_ref::<BinaryArray>().unwrap();
+ let binary_array = states[0].as_any().downcast_ref::<BinaryArray>().ok_or(
Review Comment:
It might be useful to introduce a helper function or macro for downcasting arrays to expect tyes. I think there might be one in arrow somewhere that I added a long time ago. I will try and find it.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ursabot commented on pull request #3347: Replace `unwrap` in `convert_to_ordered_float` and add `downcast_value`
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#issuecomment-1242759126
Benchmark runs are scheduled for baseline = 24f27709a687b8cb0eaa3e26744ff89ded575172 and contender = 4d22076643b3966e18e3d658bc818cca240ccd95. 4d22076643b3966e18e3d658bc818cca240ccd95 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/261998ff388140d5bba91f2f8e581140...6dcab4921bd847e784388d23c510bf83/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/e14ebc1a0fde4edfa91279e87b3475b3...74fbeda4a20c4d16bfe9d4b3498723ce/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/3a45edee3fdc49c9a89cdd82c9a87e5a...49ab133c4db443cd92632870f0d0264d/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/8557aa97d48c4b2699bc02315e49d34a...b1adebf8f1e744fbac454d46ed396325/)
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] iajoiner commented on a diff in pull request #3347: Replace `unwrap` in `convert_to_ordered_float` and add `downcast_value`
Posted by GitBox <gi...@apache.org>.
iajoiner commented on code in PR #3347:
URL: https://github.com/apache/arrow-datafusion/pull/3347#discussion_r967239752
##########
datafusion/physical-expr/src/aggregate/approx_distinct.rs:
##########
@@ -219,7 +219,11 @@ macro_rules! default_accumulator_impl {
() => {
fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
assert_eq!(1, states.len(), "expect only 1 element in the states");
- let binary_array = states[0].as_any().downcast_ref::<BinaryArray>().unwrap();
+ let binary_array = states[0].as_any().downcast_ref::<BinaryArray>().ok_or(
Review Comment:
@andygrove Fixed! Actually I expanded the macro and put it in `datafusion-common` since it is everywhere.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org