Skip to content

GH-35450: [C++] Return error when RecordBatch::ToStructArray called with mismatched column lengths - #36654

Merged
pitrou merged 1 commit into
apache:mainfrom
benibus:GH-35450-tostructarray-length-discrepancy
Aug 10, 2023
Merged

pitrou merged 1 commit into
apache:mainfrom
benibus:GH-35450-tostructarray-length-discrepancy

Conversation

@benibus

@benibus benibus commented Jul 13, 2023 •

Copy link
Copy Markdown
Contributor

Rationale for this change

If a RecordBatch is created with column lengths that don't match the provided num_rows (technically invalid), then there are some circumstances where ToStructArray will successfully return an array whose length doesn't match num_rows. Instead, we should return an error.

What changes are included in this PR?

  • Add a small validation check to ToStructArray before constructing the output array
  • Add a test

Are these changes tested?

Yes (tests are included)

Are there any user-facing changes?

No


Status ValidateBatch(const RecordBatch& batch, bool full_validation) {
for (int i = 0; i < batch.num_columns(); ++i) {
RETURN_NOT_OK(ValidateColumnLength(batch, i));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: passing array created in line 304 to ValidateColumnLength to avoid creating shared_ptr twice.

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 9b77edd.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

loicalleyne pushed a commit to loicalleyne/arrow that referenced this pull request Nov 13, 2023
…called with mismatched column lengths (apache#36654)

### Rationale for this change

If a `RecordBatch` is created with column lengths that don't match the provided `num_rows` (technically invalid), then there are some circumstances where `ToStructArray` will successfully return an array whose length doesn't match `num_rows`. Instead, we should return an error.

### What changes are included in this PR?

* Add a small validation check to `ToStructArray` before constructing the output array
* Add a test

### Are these changes tested?

Yes (tests are included)

### Are there any user-facing changes?

No

* Closes: apache#35450

Authored-by: benibus <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++] RecordBatch::ToStructArray does not respect the length of the record batch if it differs from the length of the child arrays

3 participants