-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-4975: [C++] Support concatenation of UnionArrays #11843
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
099c645
Support concatenation of UnionArrays
mbrobbel 15204d4
Handle child array length overflow
mbrobbel 4473426
Use ArrayFromJSON for dense union concatenate test
mbrobbel 57ce777
Use ArrayOf for sparse union array concatenate test
mbrobbel cff97cb
Add more tests for concatenation of dense union arrays
mbrobbel a269df9
Handle concatenation of dense union arrays with type codes other than…
mbrobbel 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
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 |
|---|---|---|
|
|
@@ -364,27 +364,171 @@ TEST_F(ConcatenateTest, DictionaryTypeNullSlots) { | |
| AssertArraysEqual(*expected, *concat_actual); | ||
| } | ||
|
|
||
| TEST_F(ConcatenateTest, DISABLED_UnionType) { | ||
| TEST_F(ConcatenateTest, UnionType) { | ||
| // sparse mode | ||
| Check([this](int32_t size, double null_probability, std::shared_ptr<Array>* out) { | ||
| auto foo = this->GeneratePrimitive<Int8Type>(size, null_probability); | ||
| auto bar = this->GeneratePrimitive<DoubleType>(size, null_probability); | ||
| auto baz = this->GeneratePrimitive<BooleanType>(size, null_probability); | ||
| auto type_ids = rng_.Numeric<Int8Type>(size, 0, 2, null_probability); | ||
| ASSERT_OK_AND_ASSIGN(*out, SparseUnionArray::Make(*type_ids, {foo, bar, baz})); | ||
| *out = rng_.ArrayOf(sparse_union({ | ||
| field("a", float64()), | ||
| field("b", boolean()), | ||
| }), | ||
| size, null_probability); | ||
| }); | ||
| // dense mode | ||
| Check([this](int32_t size, double null_probability, std::shared_ptr<Array>* out) { | ||
| auto foo = this->GeneratePrimitive<Int8Type>(size, null_probability); | ||
| auto bar = this->GeneratePrimitive<DoubleType>(size, null_probability); | ||
| auto baz = this->GeneratePrimitive<BooleanType>(size, null_probability); | ||
| auto type_ids = rng_.Numeric<Int8Type>(size, 0, 2, null_probability); | ||
| auto value_offsets = rng_.Numeric<Int32Type>(size, 0, size, 0); | ||
| ASSERT_OK_AND_ASSIGN( | ||
| *out, DenseUnionArray::Make(*type_ids, *value_offsets, {foo, bar, baz})); | ||
| *out = rng_.ArrayOf(dense_union({ | ||
bkietz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| field("a", uint32()), | ||
| field("b", boolean()), | ||
| field("c", int8()), | ||
| }), | ||
| size, null_probability); | ||
| }); | ||
| } | ||
|
|
||
| TEST_F(ConcatenateTest, DenseUnionTypeOverflow) { | ||
| // Offset overflow | ||
| auto type_ids = ArrayFromJSON(int8(), "[0]"); | ||
| auto offsets = ArrayFromJSON(int32(), "[2147483646]"); | ||
| auto child_array = ArrayFromJSON(uint8(), "[0, 1]"); | ||
| ASSERT_OK_AND_ASSIGN(auto array, | ||
| DenseUnionArray::Make(*type_ids, *offsets, {child_array})); | ||
| ArrayVector arrays({array, array}); | ||
| ASSERT_RAISES(Invalid, Concatenate(arrays, default_memory_pool())); | ||
|
|
||
| // Length overflow | ||
| auto type_ids_ok = ArrayFromJSON(int8(), "[0]"); | ||
| auto offsets_ok = ArrayFromJSON(int32(), "[0]"); | ||
| auto child_array_overflow = | ||
| this->rng_.ArrayOf(null(), std::numeric_limits<int32_t>::max() - 1, 0.0); | ||
| ASSERT_OK_AND_ASSIGN( | ||
| auto array_overflow, | ||
| DenseUnionArray::Make(*type_ids_ok, *offsets_ok, {child_array_overflow})); | ||
| ArrayVector arrays_overflow({array_overflow, array_overflow}); | ||
| ASSERT_RAISES(Invalid, Concatenate(arrays_overflow, default_memory_pool())); | ||
| } | ||
|
|
||
| TEST_F(ConcatenateTest, DenseUnionType) { | ||
| auto array = ArrayFromJSON(dense_union({field("", boolean()), field("", int8())}), R"([ | ||
| [0, true], | ||
| [0, true], | ||
| [1, 1], | ||
| [1, 2], | ||
| [0, false], | ||
| [1, 3] | ||
| ])"); | ||
| ASSERT_OK(array->ValidateFull()); | ||
|
|
||
| // Test concatenation of an unsliced array. | ||
| ASSERT_OK_AND_ASSIGN(auto concat_arrays, | ||
| Concatenate({array, array}, default_memory_pool())); | ||
| ASSERT_OK(concat_arrays->ValidateFull()); | ||
| AssertArraysEqual( | ||
| *ArrayFromJSON(dense_union({field("", boolean()), field("", int8())}), R"([ | ||
| [0, true], | ||
| [0, true], | ||
| [1, 1], | ||
| [1, 2], | ||
| [0, false], | ||
| [1, 3], | ||
| [0, true], | ||
| [0, true], | ||
| [1, 1], | ||
| [1, 2], | ||
| [0, false], | ||
| [1, 3] | ||
| ])"), | ||
| *concat_arrays); | ||
|
|
||
| // Test concatenation of a sliced array with an unsliced array. | ||
| ASSERT_OK_AND_ASSIGN(auto concat_sliced_arrays, | ||
| Concatenate({array->Slice(1, 4), array}, default_memory_pool())); | ||
| ASSERT_OK(concat_sliced_arrays->ValidateFull()); | ||
| AssertArraysEqual( | ||
| *ArrayFromJSON(dense_union({field("", boolean()), field("", int8())}), R"([ | ||
| [0, true], | ||
| [1, 1], | ||
| [1, 2], | ||
| [0, false], | ||
| [0, true], | ||
| [0, true], | ||
| [1, 1], | ||
| [1, 2], | ||
| [0, false], | ||
| [1, 3] | ||
| ])"), | ||
| *concat_sliced_arrays); | ||
|
|
||
| // Test concatenation of an unsliced array, but whose children are sliced. | ||
| auto type_ids = ArrayFromJSON(int8(), "[1, 1, 0, 0, 0]"); | ||
| auto offsets = ArrayFromJSON(int32(), "[0, 1, 0, 1, 2]"); | ||
| auto child_one = | ||
| ArrayFromJSON(boolean(), "[false, true, true, true, false, false, false]"); | ||
| auto child_two = ArrayFromJSON(int8(), "[0, 1, 1, 0, 0, 0, 0]"); | ||
| ASSERT_OK_AND_ASSIGN( | ||
| auto array_sliced_children, | ||
| DenseUnionArray::Make(*type_ids, *offsets, | ||
| {child_one->Slice(1, 3), child_two->Slice(1, 2)})); | ||
| ASSERT_OK(array_sliced_children->ValidateFull()); | ||
| ASSERT_OK_AND_ASSIGN( | ||
| auto concat_sliced_children, | ||
| Concatenate({array_sliced_children, array_sliced_children}, default_memory_pool())); | ||
| ASSERT_OK(concat_sliced_children->ValidateFull()); | ||
| AssertArraysEqual( | ||
| *ArrayFromJSON(dense_union({field("0", boolean()), field("1", int8())}), R"([ | ||
| [1, 1], | ||
| [1, 1], | ||
| [0, true], | ||
| [0, true], | ||
| [0, true], | ||
| [1, 1], | ||
| [1, 1], | ||
| [0, true], | ||
| [0, true], | ||
| [0, true] | ||
| ])"), | ||
| *concat_sliced_children); | ||
|
|
||
| // Test concatenation of a sliced array, whose children also have an offset. | ||
| ASSERT_OK_AND_ASSIGN(auto concat_sliced_array_sliced_children, | ||
| Concatenate({array_sliced_children->Slice(1, 1), | ||
| array_sliced_children->Slice(2, 3)}, | ||
| default_memory_pool())); | ||
| ASSERT_OK(concat_sliced_array_sliced_children->ValidateFull()); | ||
| AssertArraysEqual( | ||
| *ArrayFromJSON(dense_union({field("0", boolean()), field("1", int8())}), R"([ | ||
| [1, 1], | ||
| [0, true], | ||
| [0, true], | ||
| [0, true] | ||
| ])"), | ||
| *concat_sliced_array_sliced_children); | ||
|
|
||
| // Test concatenation of dense union array with types codes other than 0..n | ||
| auto array_type_codes = | ||
| ArrayFromJSON(dense_union({field("", int32()), field("", utf8())}, {2, 5}), R"([ | ||
| [2, 42], | ||
| [5, "Hello world!"], | ||
| [2, 42] | ||
| ])"); | ||
| ASSERT_OK(array_type_codes->ValidateFull()); | ||
| ASSERT_OK_AND_ASSIGN( | ||
| auto concat_array_type_codes, | ||
| Concatenate({array_type_codes, array_type_codes, array_type_codes->Slice(1, 1)}, | ||
| default_memory_pool())); | ||
| ASSERT_OK(concat_array_type_codes->ValidateFull()); | ||
| AssertArraysEqual( | ||
| *ArrayFromJSON(dense_union({field("", int32()), field("", utf8())}, {2, 5}), | ||
| R"([ | ||
| [2, 42], | ||
| [5, "Hello world!"], | ||
| [2, 42], | ||
| [2, 42], | ||
| [5, "Hello world!"], | ||
| [2, 42], | ||
| [5, "Hello world!"] | ||
| ])"), | ||
| *concat_array_type_codes); | ||
| } | ||
|
Member
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. Can we also test concatenation of an array 1) which is not sliced, but whose children are sliced/have an offset? 2) which is sliced, whose children additionally have an offset? |
||
|
|
||
| TEST_F(ConcatenateTest, OffsetOverflow) { | ||
| auto fake_long = ArrayFromJSON(utf8(), "[\"\"]"); | ||
| fake_long->data()->GetMutableValues<int32_t>(1)[1] = | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.