Repository navigation
GH-55295: [C++][Dataset] Reject negative num_rows in Scanner::Head - #55304
Open
siddiqueirshad wants to merge 1 commit into
Open
siddiqueirshad wants to merge 1 commit into
siddiqueirshad wants to merge 1 commit into
Conversation
Fixes apache#55295 Signed-off-by: siddiqui irshad <[email protected]>
|
|
|
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rationale for this change
Fixes #55295. Currently,
Dataset.head,Scanner.head, andFragment.headaccept negativenum_rows(e.g.head(-1)).AsyncScanner::Headpasses the negative count directly intoRecordBatch::Slice(0, num_rows), producing invalid record batches with negative lengths that causeTable.validate()to fail withArray length is negativeandlen()in Python to fail withSystemError.What changes are included in this PR?
AsyncScanner::Head, checkif (num_rows < 0)and returnStatus::Invalid("num_rows must be non-negative").cpp/src/arrow/dataset/scanner_test.cc, addASSERT_RAISES(Invalid, scanner->Head(-1))toTestScanner.Head.python/pyarrow/tests/test_dataset.py, test that negative rows raiseValueError(asArrowInvalidsubclassesValueError) for bothdataset_reader.head(dataset, -1)andfragment.head(-1).Are these changes tested?
Yes, added C++ unit test in
scanner_test.ccand Python tests intest_dataset.py.Are there any user-facing changes?
Yes, calling
head()with a negativenum_rowsnow returns anArrowInvaliderror instead of returning a malformed Table with negative row count.Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by: