-
Notifications
You must be signed in to change notification settings - Fork 4.2k
GH-50508: [C++] Support scalar values in AppendScalars #50584
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
Open
Moemenmohamed24
wants to merge
3
commits into
apache:main
Choose a base branch
from
Moemenmohamed24:GH-50508-append-scalars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
−3
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -227,7 +227,6 @@ TEST_P(TestRunEndEncodedArray, LogicalRunEnds) { | |||||||
| ASSERT_OK_AND_ASSIGN(logical_run_ends, ree_slice->LogicalRunEnds(pool)); | ||||||||
| ASSERT_ARRAYS_EQUAL(*logical_run_ends, *expected_run_ends); | ||||||||
| } | ||||||||
|
|
||||||||
| TEST_P(TestRunEndEncodedArray, Builder) { | ||||||||
| auto value_type = utf8(); | ||||||||
| auto ree_type = run_end_encoded(run_end_type, value_type); | ||||||||
|
|
@@ -366,6 +365,71 @@ TEST_P(TestRunEndEncodedArray, Builder) { | |||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| TEST_P(TestRunEndEncodedArray, BuilderAppendScalarsPrimitiveScalar) { | ||||||||
| auto value_type = float32(); | ||||||||
| auto ree_type = run_end_encoded(run_end_type, value_type); | ||||||||
|
|
||||||||
| ASSERT_OK_AND_ASSIGN(std::shared_ptr<ArrayBuilder> builder, MakeBuilder(ree_type)); | ||||||||
|
|
||||||||
| ASSERT_OK_AND_ASSIGN(auto v1, MakeScalar(float32(), 1.0f)); | ||||||||
| ASSERT_OK_AND_ASSIGN(auto v2, MakeScalar(float32(), 1.0f)); | ||||||||
| ASSERT_OK_AND_ASSIGN(auto v3, MakeScalar(float32(), 2.0f)); | ||||||||
| ASSERT_OK_AND_ASSIGN(auto v4, MakeScalar(float32(), 2.0f)); | ||||||||
| ASSERT_OK_AND_ASSIGN(auto v5, MakeScalar(float32(), 3.0f)); | ||||||||
|
|
||||||||
| ScalarVector scalars = {v1, v2, v3, v4, v5}; | ||||||||
|
|
||||||||
| ASSERT_OK(builder->AppendScalars(scalars)); | ||||||||
|
|
||||||||
| ASSERT_EQ(builder->length(), 5); | ||||||||
|
|
||||||||
| ASSERT_OK_AND_ASSIGN(auto array, builder->Finish()); | ||||||||
|
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. Let's also validate the result:
Suggested change
|
||||||||
|
|
||||||||
| auto ree_array = std::dynamic_pointer_cast<RunEndEncodedArray>(array); | ||||||||
|
|
||||||||
| ASSERT_NE(ree_array, NULLPTR); | ||||||||
|
|
||||||||
| auto expected_run_ends = ArrayFromJSON(run_end_type, "[2,4,5]"); | ||||||||
|
|
||||||||
| auto expected_values = ArrayFromJSON(float32(), "[1,2,3]"); | ||||||||
|
|
||||||||
| ASSERT_ARRAYS_EQUAL(*expected_run_ends, *ree_array->run_ends()); | ||||||||
|
|
||||||||
| ASSERT_ARRAYS_EQUAL(*expected_values, *ree_array->values()); | ||||||||
| } | ||||||||
|
|
||||||||
| TEST_P(TestRunEndEncodedArray, BuilderAppendScalarsRunEndEncodedScalar) { | ||||||||
| auto value_type = float32(); | ||||||||
| auto ree_type = run_end_encoded(run_end_type, value_type); | ||||||||
|
|
||||||||
| ASSERT_OK_AND_ASSIGN(std::shared_ptr<ArrayBuilder> builder, MakeBuilder(ree_type)); | ||||||||
|
|
||||||||
| ASSERT_OK_AND_ASSIGN(auto s1, MakeScalar(ree_type, *MakeScalar(float32(), 1.0f))); | ||||||||
| ASSERT_OK_AND_ASSIGN(auto s2, MakeScalar(ree_type, *MakeScalar(float32(), 1.0f))); | ||||||||
| ASSERT_OK_AND_ASSIGN(auto s3, MakeScalar(ree_type, *MakeScalar(float32(), 2.0f))); | ||||||||
| ASSERT_OK_AND_ASSIGN(auto s4, MakeScalar(ree_type, *MakeScalar(float32(), 2.0f))); | ||||||||
| ASSERT_OK_AND_ASSIGN(auto s5, MakeScalar(ree_type, *MakeScalar(float32(), 3.0f))); | ||||||||
|
|
||||||||
| ScalarVector scalars = {s1, s2, s3, s4, s5}; | ||||||||
|
|
||||||||
| ASSERT_OK(builder->AppendScalars(scalars)); | ||||||||
|
|
||||||||
| ASSERT_EQ(builder->length(), 5); | ||||||||
|
|
||||||||
| ASSERT_OK_AND_ASSIGN(auto array, builder->Finish()); | ||||||||
|
|
||||||||
| auto ree_array = std::dynamic_pointer_cast<RunEndEncodedArray>(array); | ||||||||
|
|
||||||||
| ASSERT_NE(ree_array, NULLPTR); | ||||||||
|
|
||||||||
| auto expected_run_ends = ArrayFromJSON(run_end_type, "[2,4,5]"); | ||||||||
|
|
||||||||
| auto expected_values = ArrayFromJSON(float32(), "[1,2,3]"); | ||||||||
|
|
||||||||
| ASSERT_ARRAYS_EQUAL(*expected_run_ends, *ree_array->run_ends()); | ||||||||
|
|
||||||||
| ASSERT_ARRAYS_EQUAL(*expected_values, *ree_array->values()); | ||||||||
| } | ||||||||
|
|
||||||||
| TEST_P(TestRunEndEncodedArray, BuilderReuseAfterFinish) { | ||||||||
| // GH-45532: RunEndEncodedBuilder should clear dimensions after a Finish() call | ||||||||
|
|
||||||||
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 |
|---|---|---|
|
|
@@ -201,7 +201,6 @@ Status RunEndEncodedBuilder::AppendEmptyValues(int64_t length) { | |
| UpdateDimensions(committed_logical_length_, 0); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
|
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. OTOH, let's please keep an empty line between function and method definitions. |
||
| Status RunEndEncodedBuilder::AppendScalar(const Scalar& scalar, int64_t n_repeats) { | ||
| if (scalar.type->id() == Type::RUN_END_ENCODED) { | ||
| return AppendScalar(*internal::checked_cast<const RunEndEncodedScalar&>(scalar).value, | ||
|
|
@@ -213,7 +212,10 @@ Status RunEndEncodedBuilder::AppendScalar(const Scalar& scalar, int64_t n_repeat | |
| } | ||
|
|
||
| Status RunEndEncodedBuilder::AppendScalars(const ScalarVector& scalars) { | ||
| RETURN_NOT_OK(this->ArrayBuilder::AppendScalars(scalars)); | ||
| if (scalars.empty()) return Status::OK(); | ||
| for (const auto& scalar : scalars) { | ||
| RETURN_NOT_OK(AppendScalar(*scalar, 1)); | ||
| } | ||
| UpdateDimensions(committed_logical_length_, value_run_builder_->open_run_length()); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
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.
There's no need to add an empty line after each individual statement, can we compact this a bit and only keep empty lines to distinguish between logically different sequences?