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

Use try_new when casting between structs to propagate error #5226

Merged
merged 3 commits into from Dec 20, 2023

Conversation

viirya
Copy link
Member

@viirya viirya commented Dec 19, 2023

Which issue does this PR close?

Closes #.

Rationale for this change

Different to casting from primitive types, casting between structs needs to consider nullability as the fields of structs have nullability properties. We use StructArray::new when casting structs for now which simply fails. We should use StructArray::try_new to propagate the error.

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Dec 19, 2023
@@ -160,11 +160,18 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
(Decimal128(_, _) | Decimal256(_, _), Utf8 | LargeUtf8) => true,
// Utf8 to decimal
(Utf8 | LargeUtf8, Decimal128(_, _) | Decimal256(_, _)) => true,
(Struct(from_fields), Struct(to_fields)) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Btw, "tab" was used in the merged code. It made incorrect ident in diff display. I fixed it to use space.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to update can_cast_types?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean tab -> space fix or the added comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is better to fix the tab with space, otherwise the diff always shows a wrong indent.

The comment is good to have to explain why nullability is ignored there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I saw modifications and thought you hadn't updated this 😅

arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
@tustvold
Copy link
Contributor

tustvold commented Dec 19, 2023

Perhaps we could use StructArray::try_new which will validate nullability and return an error, if we aren't already. I think this would still preserve the invariant that nullable columns don't obtain nulls?

Or to phrase it differently, the array constructors already verify this, so perhaps this is sufficient??

@viirya
Copy link
Member Author

viirya commented Dec 20, 2023

Perhaps we could use StructArray::try_new which will validate nullability and return an error, if we aren't already. I think this would still preserve the invariant that nullable columns don't obtain nulls?

Or to phrase it differently, the array constructors already verify this, so perhaps this is sufficient??

Ah, that's good to know StructArray already does the check. But currently the cast kernel doesn't use try_new but new which doesn't propagate the error back. Let me update it and add corresponding test.

Thanks.

@viirya viirya changed the title Consider nullability when casting between structs Use try_new when casting between structs Dec 20, 2023
@viirya viirya changed the title Use try_new when casting between structs Use try_new when casting between structs to propagate error Dec 20, 2023
@viirya viirya changed the title Use try_new when casting between structs to propagate error Use try_new when casting between structs to propagate error Dec 20, 2023
@tustvold tustvold merged commit 1fa7afd into apache:master Dec 20, 2023
25 checks passed
@viirya
Copy link
Member Author

viirya commented Dec 20, 2023

Thank you @tustvold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants