Repository navigation
cast_variant skips unsupported target type validation for empty inputs #23462
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
94f8bf1
bugfix
ba2a9c5
Merge branch 'main' into ak/cast-variant-bugfix
2521d98
Merge branch 'main' into ak/cast-variant-bugfix
6d70b72
changed type
c1e0e9d
Merge branch 'ak/cast-variant-bugfix' of github.com:abigalekim/cudf i…
1cd9b98
merge changes
b0d37be
coderabbit
b4495ac
reviews
df6e561
Merge branch 'main' into ak/cast-variant-bugfix
32d492a
addressing reviews
704c9bd
Merge branch 'main' into ak/cast-variant-bugfix
1c3ef72
Merge branch 'main' into ak/cast-variant-bugfix
480db43
Merge branch 'main' into ak/cast-variant-bugfix
f73a15d
Merge branch 'main' into ak/cast-variant-bugfix
b35620a
Merge branch 'main' into ak/cast-variant-bugfix
d476b81
Merge fixes from boolean PR
047d5bb
Merge branch 'main' into ak/cast-variant-bugfix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| #include <cudf/utilities/span.hpp> | ||
|
|
||
| #include <array> | ||
| #include <bit> | ||
| #include <cstdio> | ||
| #include <cstring> | ||
| #include <memory> | ||
|
|
@@ -1032,11 +1033,9 @@ TEST_F(CastVariantTest, EmptyInput) | |
| } | ||
| } | ||
|
|
||
| TEST_F(CastVariantTest, CastToUnsupportedTargetThrows) | ||
| TEST_F(CastVariantTest, UnsupportedTypeThrows) | ||
| { | ||
| // cast_variant only supports INT8/16/32/64 and STRING targets. Every other target is rejected at | ||
| // compile-time dispatch on the requested output type, independent of the input bytes, so a single | ||
| // well-formed placeholder row triggers the same throw for all of them. | ||
| // Unsupported target types must throw regardless of whether the input is empty or non-empty. | ||
| auto stream = cudf::test::get_default_stream(); | ||
| std::vector<uint8_t> const val{make_variant_primitive(variant_primitive_type::NULLVAL)}; | ||
| cudf::test::lists_column_wrapper<uint8_t> values(val.begin(), val.end()); | ||
|
abigalekim marked this conversation as resolved.
Resolved
|
||
|
|
@@ -1053,11 +1052,24 @@ TEST_F(CastVariantTest, CastToUnsupportedTargetThrows) | |
| cudf::type_id::DECIMAL64, | ||
| cudf::type_id::DECIMAL128}; | ||
|
|
||
| // Empty input: the early-return path must still validate the type. | ||
| auto const empty_values = | ||
| cudf::empty_like(cudf::structs_column_view{make_xyz_three_row_variant()}.child(1)); | ||
| for (auto const& id : ids) { | ||
|
abigalekim marked this conversation as resolved.
Resolved
|
||
| EXPECT_THROW(static_cast<void>(cudf::io::parquet::experimental::cast_variant( | ||
| *empty_values, cudf::data_type{id}, stream)), | ||
| std::invalid_argument) | ||
| << "expected throw for type_id " << static_cast<int>(id) << " on empty input"; | ||
|
abigalekim marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| // Non-empty input: the dispatch path must also throw for unsupported types. | ||
| auto col = make_apache_variant(avf::primitive_int32); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚁🚁🚁 (iykyk 😄) |
||
| auto const value = cudf::structs_column_view{col}.get_sliced_child(1, stream); | ||
| for (auto const id : ids) { | ||
| SCOPED_TRACE(std::string{"target type_id: "} + std::to_string(static_cast<int32_t>(id))); | ||
| EXPECT_THROW(static_cast<void>(cudf::io::parquet::experimental::cast_variant( | ||
| values, cudf::data_type{id}, stream)), | ||
| std::invalid_argument); | ||
| value, cudf::data_type{id}, stream)), | ||
| std::invalid_argument) | ||
| << "expected throw for type_id " << static_cast<int>(id) << " on non-empty input"; | ||
|
abigalekim marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can get rid of the type dispatcher here. It's generally quite expensive and the functor being dispatch seems trivial enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I have refactored it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment only referred to
validate_variant_type_fn, not the entire cast. I'm not sure that we want all casting in a single function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have re-refactored it to address this comment!