Skip to content
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

Remove redundant unwrap in ScalarValue::new_primitive, return a Result #7830

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

maruschin
Copy link
Contributor

@maruschin maruschin commented Oct 16, 2023

Which issue does this PR close?

It's a part of #3313.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the physical-expr Physical Expressions label Oct 16, 2023
@maruschin maruschin force-pushed the remove_redundant_unwrap branch 10 times, most recently from 291f741 to 6de516d Compare October 16, 2023 12:45
@maruschin maruschin marked this pull request as ready for review October 16, 2023 13:10
@maruschin maruschin changed the title Remove redundant unwrap in datafusion-common crate Remove redundant unwrap in ScalarValue::new_primitive Oct 16, 2023
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

This looks good to me -- while it is an API change I think it is a reasonable one. Thank you @maruschin

I noticed the comments also need to be updated but we could also do that as a follow on PR as well

@@ -744,13 +744,13 @@ impl ScalarValue {
pub fn new_primitive<T: ArrowPrimitiveType>(
a: Option<T::Native>,
d: &DataType,
) -> Self {
) -> Result<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the comments in this function also need to be updated (the 'panic's section is no longer correct)

    /// Create a [`ScalarValue`] with the provided value and datatype
    ///
    /// # Panics
    ///
    /// Panics if d is not compatible with T

Copy link
Contributor

@tustvold tustvold Oct 16, 2023

Choose a reason for hiding this comment

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

with_data_type can still panic, I personally don't see anything wrong with this FWIW, panic are a perfectly valid way to handle unexpected failure imo

Copy link
Contributor

@alamb alamb Oct 16, 2023

Choose a reason for hiding this comment

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

Wrong with what? As in it is fine if this function panics and there is no need to propagate the error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Its an exceptional case that would imply some sort of schema inconsistency within the running plan, so imo panicking is perfectly valid, but then so is returning an error. The broader point is the doc is still correct

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the point about the panics -- thank you

I don't have a strong opinion either way with regards to propagating errors vs panic'ing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alamb, I rewrote the comment and left a mention about panic. As @tustvold metioned with_data_type can panic.

@alamb alamb changed the title Remove redundant unwrap in ScalarValue::new_primitive Remove redundant unwrap in ScalarValue::new_primitive Oct 16, 2023
@alamb alamb changed the title Remove redundant unwrap in ScalarValue::new_primitive Remove redundant unwrap in ScalarValue::new_primitive, return a Result Oct 16, 2023
@alamb alamb added the api change Changes the API exposed to users of the crate label Oct 16, 2023
@maruschin maruschin force-pushed the remove_redundant_unwrap branch 3 times, most recently from a7f55b8 to 5befee1 Compare October 17, 2023 00:42
@Dandandan Dandandan merged commit efbd104 into apache:main Oct 17, 2023
22 checks passed
@Dandandan
Copy link
Contributor

Thanks @maruschin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants