-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-16977: [R] Update dataset row counting so no integer overflow on large datasets #13514
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
ARROW-16977: [R] Update dataset row counting so no integer overflow on large datasets #13514
Conversation
|
|
nealrichardson
left a comment
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.
Thanks! Two questions:
- I don't see a test of the
r_vec_size()behavior in this PR or the other one. What is our assurance that it behaves as we want? - I noticed that this function previously returned
int64_t, so I wondered whether cpp11 just automatically handled that in the way we wanted. [Turns out someone 🤦 already found out that this doesn't behave nicely], and that we need to handle it ourselves like you have done here. Unfortunately, we have about 20 other functions that return int64_t that would be subject to the same overflow problem. (I searched^int64_tinr/src/to find them.) Would you mind fixing them all in this PR too?
|
Also, it looks like you need to install the package/run the codegen script so that arrowExports.cpp gets updated. |
I added some in an earlier version of the previous PR, but they took ages to run locally (though were successful), and on CI just crashed it entirely. I removed them, but couldn't think of an alternative. Do you have any suggestions?
Done. |
You could tack onto one of the tests that is guarded by |
| ) | ||
| }) | ||
|
|
||
| test_that("num_rows method not susceptible to integer overflow", { |
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.
These large memory tests are slow, so I don't think you need two versions, I think you can keep just the Table version.
If you want to test more places r_vec_size is used, you can get $nbytes() on the arrays/chunkedarrays, as well as length(). You can also get array$data() and check its length (that one might not be covered yet...) and get $buffers from that, and check them too.
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've removed the RecordBatch test, added in tests for a few more fields, as well as updating a couple of utility functions that these changes broke. The one thing I didn't do is getting array$data() and actually, I'm wondering if overflow is possible with that? From my understanding, an array's maximum size would be the maximum integer value, or am I getting mixed up there?
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.
LargeString/Binary at least have a buffer size that can go up to MAX_INT64, that's why they exist.
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.
@nealrichardson Would you mind expanding on that a bit? There's something I'm missing here or misunderstanding.
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.
On the format, see https://github.com/apache/arrow/blob/master/format/Schema.fbs#L155-L171 and https://arrow.apache.org/docs/format/Columnar.html.
In R:
# Here's a simple integer array
> a <- Array$create(1:5)
> a$data()
ArrayData
> a$data()$buffers
[[1]]
NULL
[[2]]
Buffer
# the first buffer is for the null bitmask, but it's empty because there are no NAs
> a$data()$buffers[[2]]
Buffer
> a$data()$buffers[[2]]$size
[1] 20
> a$data()$buffers[[2]]$capacity
[1] 20
# here's a string array
> strings <- Array$create(letters)
# note it has 3 buffers, one for the data and one for the offsets
> strings$data()$buffers
[[1]]
NULL
[[2]]
Buffer
[[3]]
Buffer
> strings$data()$buffers[[2]]$size
[1] 108
> strings$data()$buffers[[3]]$size
[1] 26
# let's make a LargeString array using the helper from the test suite
> make_big_string <- function() {
+ # This creates a character vector that would exceed the capacity of BinaryArray
+ rep(purrr::map_chr(2047:2050, ~ paste(sample(letters, ., replace = TRUE), collapse = "")), 2^18)
+ }
> big <- Array$create(make_big_string())
> big$type
LargeUtf8
large_string
> big$data()$buffers
[[1]]
NULL
[[2]]
Buffer
[[3]]
Buffer
> big$data()$buffers[[2]]$size
[1] 8388616
# the data buffer is > MAX_INT32 so it overflows (on master)
> big$data()$buffers[[3]]$size
[1] -2146959360
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.
Thank you for that! Worked out what it was - I'd completely forgotten R's issues with 64 bit integers for a moment there.
|
Benchmark runs are scheduled for baseline = 5d86e9f and contender = 87d1889. 87d1889 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
…Hub issue numbers (#34260) Rewrite the Jira issue numbers to the GitHub issue numbers, so that the GitHub issue numbers are automatically linked to the issues by pkgdown's auto-linking feature. Issue numbers have been rewritten based on the following correspondence. Also, the pkgdown settings have been changed and updated to link to GitHub. I generated the Changelog page using the `pkgdown::build_news()` function and verified that the links work correctly. --- ARROW-6338 #5198 ARROW-6364 #5201 ARROW-6323 #5169 ARROW-6278 #5141 ARROW-6360 #5329 ARROW-6533 #5450 ARROW-6348 #5223 ARROW-6337 #5399 ARROW-10850 #9128 ARROW-10624 #9092 ARROW-10386 #8549 ARROW-6994 #23308 ARROW-12774 #10320 ARROW-12670 #10287 ARROW-16828 #13484 ARROW-14989 #13482 ARROW-16977 #13514 ARROW-13404 #10999 ARROW-16887 #13601 ARROW-15906 #13206 ARROW-15280 #13171 ARROW-16144 #13183 ARROW-16511 #13105 ARROW-16085 #13088 ARROW-16715 #13555 ARROW-16268 #13550 ARROW-16700 #13518 ARROW-16807 #13583 ARROW-16871 #13517 ARROW-16415 #13190 ARROW-14821 #12154 ARROW-16439 #13174 ARROW-16394 #13118 ARROW-16516 #13163 ARROW-16395 #13627 ARROW-14848 #12589 ARROW-16407 #13196 ARROW-16653 #13506 ARROW-14575 #13160 ARROW-15271 #13170 ARROW-16703 #13650 ARROW-16444 #13397 ARROW-15016 #13541 ARROW-16776 #13563 ARROW-15622 #13090 ARROW-18131 #14484 ARROW-18305 #14581 ARROW-18285 #14615 * Closes: #33631 Authored-by: SHIMA Tatsuya <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
Follow up to #13482 after this one was missed.