Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-46224: [C++][Acero] Fix the hang in asof join#46300
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b4b0cf8
Draft the fix
zanmato1984 d1e11ae
Fix build
zanmato1984 f1397a1
Delete cpp/src/arrow/compute/row/doc/row_table.md
zanmato1984 4b9db70
Remove hack for reproduction
zanmato1984 ecf58a0
Remove hack for reproduction
zanmato1984 af70071
Describe the test
zanmato1984 3a273b3
Update cpp/src/arrow/acero/asof_join_node.cc
zanmato1984 dd7a66b
Update test according to the review comment
zanmato1984 5f5b895
Reduce test iteration for sanitizier and valgrind
zanmato1984 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 |
|---|---|---|
| @@ -44,6 +44,7 @@ | ||
| #include "arrow/compute/cast.h" | ||
| #include "arrow/compute/row/row_encoder_internal.h" | ||
| #include "arrow/compute/test_util_internal.h" | ||
| #include "arrow/testing/generator.h" | ||
| #include "arrow/testing/gtest_util.h" | ||
| #include "arrow/testing/matchers.h" | ||
| #include "arrow/testing/random.h" | ||
| @@ -1770,5 +1771,58 @@ TEST(AsofJoinTest, DestroyNonStartedAsofJoinNode) { | ||
| DeclarationToStatus(std::move(sink))); | ||
| } | ||
| // Reproduction of GH-46224: Hang when all left timestamps are greater than right | ||
| // timestamps. | ||
pitrou marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| TEST(AsofJoinTest, OneSideTsAllGreaterThanTheOther) { | ||
zanmato1984 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| #if defined(ARROW_VALGRIND) || defined(ADDRESS_SANITIZER) | ||
| const int rounds = 1; | ||
| #else | ||
| const int rounds = 42; | ||
| #endif | ||
| int64_t tolerance = 1; | ||
| int64_t num_rows_big_ts = 1; | ||
| int64_t num_rows_small_ts = ExecPlan::kMaxBatchSize + 1; | ||
| // Make sure the big_ts is outside the horizon of the tolerance regardless of the side. | ||
| int64_t big_ts = num_rows_small_ts + tolerance + 1; | ||
| // Column of big timestamps. | ||
| ASSERT_OK_AND_ASSIGN(auto col_big_ts, | ||
| gen::Constant(MakeScalar(big_ts))->Generate(num_rows_big_ts)); | ||
| // Column of small timestamps from 0 to num_rows_small_ts - 1. | ||
| ASSERT_OK_AND_ASSIGN(auto col_small_ts, | ||
| gen::Step<int64_t>()->Generate(num_rows_small_ts)); | ||
| struct Case { | ||
| std::shared_ptr<arrow::Array> left_col; | ||
| std::shared_ptr<arrow::Array> right_col; | ||
| }; | ||
| for (const auto& c : { | ||
| Case{col_big_ts, col_small_ts}, | ||
| Case{col_small_ts, col_big_ts}, | ||
| }) { | ||
| auto left_schema = arrow::schema({arrow::field("on", int64())}); | ||
| auto right_schema = arrow::schema({arrow::field("on", int64())}); | ||
| ExecBatch left_batch({c.left_col}, c.left_col->length()); | ||
| ExecBatch right_batch({c.right_col}, c.right_col->length()); | ||
| ASSERT_OK_AND_ASSIGN(auto col_null, MakeArrayOfNull(int64(), c.left_col->length())); | ||
| ExecBatch exp_batch({c.left_col, col_null}, c.left_col->length()); | ||
| // Run moderate number of times to ensure that no hangs occur. | ||
| for (int i = 0; i < rounds; ++i) { | ||
| AsofJoinNodeOptions opts({{{"on"}, {}}, {{"on"}, {}}}, tolerance); | ||
| auto left = Declaration("exec_batch_source", | ||
| ExecBatchSourceNodeOptions(left_schema, {left_batch})); | ||
| auto right = Declaration("exec_batch_source", | ||
| ExecBatchSourceNodeOptions(right_schema, {right_batch})); | ||
| auto asof_join = arrow::acero::Declaration{"asofjoin", {left, right}, opts}; | ||
| ASSERT_OK_AND_ASSIGN(auto result, | ||
| arrow::acero::DeclarationToExecBatches(std::move(asof_join))); | ||
| AssertExecBatchesEqualIgnoringOrder(result.schema, {exp_batch}, result.batches); | ||
| } | ||
| } | ||
| } | ||
| } // namespace acero | ||
| } // namespace arrow | ||
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.
IMO this code is apparently NOT doing what it is supposed to do: by here the
have_active_batchmust betrue, meaningqueue_must be non-empty. Then popping the queue always gets a validstd::optionaland effectively settinghave_active_batchto false. Theifbranch below won't be executed.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 noticed there are two fixes made before in the following
ifbranch #36094 and #36499. Given that thishave_active_batch &= !queue_.TryPop()exists since #13028 where it was introduced, and the lack of corresponding tests, I'm not sure how they fixed anything and what the bugs even were. So I just remove them.