Skip to content

GH-50339: [R] read_ipc_stream fails to unify nested uint64 fields inside a Struct array across record batches#50374

Merged
thisisnic merged 6 commits into
apache:mainfrom
thisisnic:GH-50339-nesteduint64
Jul 9, 2026
Merged

GH-50339: [R] read_ipc_stream fails to unify nested uint64 fields inside a Struct array across record batches#50374
thisisnic merged 6 commits into
apache:mainfrom
thisisnic:GH-50339-nesteduint64

Conversation

@thisisnic

@thisisnic thisisnic commented Jul 5, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Attempting downcasting on UINT64 Fields when converting them from Arrow to R works fine on individual arrays, but fails on list arrays, because we only use the individual row to work out whether to downcast.

I considered a few different solutions but I concluded that this one is the least complex while presenting a good solution - having UINT64 always be converted to doubles and never attempt downcasting.

The impact here is that people who are expecting integers via downcasting will see a change in behaviour, but I think there's a strong argument here that if you are using UINT64 to store values that can be downcast, you probably need to be using UINT32 anyway.

Other options considered: fix this in Converter_List and check values to see if they can be downcast: significantly more complex and only fixes one level of nesting.

I checked duckdb and they always convert UINT64 to doubles.

What changes are included in this PR?

Never try to downcast UNIT64 values when converting to R

Are these changes tested?

Yes

Are there any user-facing changes?

Breaking change as mentioned in rationale above.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #50339 has been automatically assigned in GitHub to PR creator.

@thisisnic thisisnic marked this pull request as ready for review July 8, 2026 08:54
@thisisnic thisisnic requested a review from jonkeane as a code owner July 8, 2026 08:54
Copilot AI review requested due to automatic review settings July 8, 2026 08:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses inconsistent type unification for nested uint64 fields when converting Arrow data (e.g., from read_ipc_stream()) into R, by making uint64 always convert to R numeric (double) to ensure consistent nested/list-column element types across record batches.

Changes:

  • Update the R conversion path to always map Arrow uint64 to double (no downcasting to integer).
  • Add/adjust unit tests to cover both top-level and nested/list uint64 conversions (GH-50339).
  • Update user-facing docs and release notes to reflect the breaking behavior change.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
r/src/array_to_vector.cpp Always uses the double converter for UINT64.
r/tests/testthat/test-Array.R Updates existing uint32 expectations and adds new coverage for uint64 always converting to double, including inside list columns.
r/vignettes/data_types.Rmd Updates vignette text/table to document uint64double behavior.
r/R/type.R Updates roxygen documentation for integer type translations, reflecting uint64 always as double.
r/man/data-type.Rd Mirrors the updated documentation in the generated Rd.
r/NEWS.md Adds a breaking-change note for uint64 conversion behavior (#50339).
r/src/arrowExports.cpp Reorders generated export glue for Field helpers (no functional change intended).
r/man/acero.Rd Updates the documented compute-function count.
Files not reviewed (2)
  • r/man/acero.Rd: Generated file
  • r/man/data-type.Rd: Generated file

Comment thread r/vignettes/data_types.Rmd Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 08:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.

Files not reviewed (2)
  • r/man/acero.Rd: Generated file
  • r/man/data-type.Rd: Generated file

Comment thread r/tests/testthat/test-Array.R Outdated
Comment thread r/man/acero.Rd Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 10:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • r/man/acero.Rd: Generated file
  • r/man/data-type.Rd: Generated file

Comment thread r/man/acero.Rd Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 14:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • r/man/data-type.Rd: Generated file

Comment thread r/vignettes/data_types.Rmd Outdated
When translating from Arrow to R, integer types always translate to R integers unless one of the following exceptions applies:

- If the value of an Arrow uint32 or uint64 falls outside the range allowed for R integers, the result will be a numeric vector in R
- Arrow uint64 types are always converted to numeric (double) vectors in R
Comment thread r/R/type.R
Comment on lines +359 to +363
#' `uint64` (64 bit unsigned integer) is always converted to `double`
#' ("numeric") in R. `uint32` (32 bit unsigned integer) and `int64` (64-bit
#' signed integer) types may contain values that exceed the range of R's
#' `integer` type (32-bit signed integer). When they do, `uint32` is converted
#' to `double` ("numeric") and `int64` is converted to `bit64::integer64`. For

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.

I agree with this comment, though it might make this a bit too verbose? But having some detail that there is a loss of precision here is good to call out

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added something hopefully brief enough to be less verbose

@jonkeane jonkeane left a comment

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.

I'm ok with this if the tests are happy. I'm not sure I 100% understand the usecase that is causing this, but the logic makes sense.

Comment thread r/vignettes/data_types.Rmd
Comment thread r/R/type.R
Comment on lines +359 to +363
#' `uint64` (64 bit unsigned integer) is always converted to `double`
#' ("numeric") in R. `uint32` (32 bit unsigned integer) and `int64` (64-bit
#' signed integer) types may contain values that exceed the range of R's
#' `integer` type (32-bit signed integer). When they do, `uint32` is converted
#' to `double` ("numeric") and `int64` is converted to `bit64::integer64`. For

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.

I agree with this comment, though it might make this a bit too verbose? But having some detail that there is a loss of precision here is good to call out

@github-actions github-actions Bot added awaiting merge Awaiting merge and removed awaiting committer review Awaiting committer review labels Jul 8, 2026
Copilot AI review requested due to automatic review settings July 9, 2026 11:31
@thisisnic thisisnic merged commit ad4d8ac into apache:main Jul 9, 2026
32 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • r/man/data-type.Rd: Generated file

Comment on lines 104 to +108
- If the user sets `options(arrow.int64_downcast = FALSE)`, the Arrow int64 type always yields a `bit64::integer64` vector in R
regardless of the value
- Arrow uint64 types are always converted to numeric (double) vectors in R.
Note that doubles cannot exactly represent all uint64 values; precision may
be lost for values above 2^53.
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.

3 participants