Repository navigation
Description
Describe the bug, including details regarding any error messages, version, and platform.
read_parquet() is giving the following error with large parquet files:
Capacity error: array cannot contain more than 2147483646 bytes, have 2147489180
Versions etc from sessionInfo:
- arrow 14.0.0.2
- R version 4.3.0 (2023-04-21 ucrt)
- Platform: x86_64-w64-ming32/x64
- Windows 11 x64 (build 22621)
Descriptive info on example problematic table, with two columns:
- 140 million rows.
- id: large_string, 4.2 Gb
- state: int_32, 0.5 Gb
The id is a hashed string, 24 characters long. It is not practical to change it, as it's the joining key.
Note, the data above is stored as a data.table in R and left that way when saving it with write_parquet(). But I've converted it to an arrow table for the above descriptive stats, because I thought they'd be more useful to you!
Other relevant information:
- The large parquet files were created with arrow::write_parquet()
- The same files previously opened with an earlier version of read_parquet()
(unfortunately I'm not sure which version, but it was working late November/early December, we work in a closed environment and use Posit Package manager, VMs rebuild every 30 days, so it would have been a fairly recent version) - I've duplicated the error, and it still occurs with newly created large parquet files, such as the one described above
- Loading the same files with open_dataset() works. However, our team uses targets, which implicitly calls read_parquet, so this bug has unfortunately efffected many of our workflows.
Note: I haven't been able to roll back to an earlier version of arrow - because we only have earlier source versions and not binaries and I'm using windows, I get libarrow errors. If there is a work around for this please let me know.
UPDATE
With the help of IT, I have been able to install earlier versions of arrow in my environment, and have shown that:
- Bug was introduced in arrow version 14.0.0, and it's the read_parquet function that is the issue, not write_parquet.
- With version 13.0.0.1 I was able to open the above problematic file, which was created with write_parquet version 14.0.0.2.
Component(s)
Parquet, R
Activity
assignUser commentedon Jan 18, 2024
devtools::install_version('arrow', '13.0.0.1')works for me on windows. It does need to download a binary so that might get blocked? If that's the case you can get the binary manually here and then set the envvarRWINLIB_LOCALto point to the zip file.nicki-dese commentedon Jan 18, 2024
@assignUser - thank you! unfortunately the closed environment does not connect to the internet. I will point the IT team who I've asked for help with this internally at that link and see if they'd be willing to test or upload it for me so I can test.
nicki-dese commentedon Jan 22, 2024
Given that the bug was introduced in version 14.0.0, I am wondering if it relates to #37274
thisisnic commentedon Jan 30, 2024
@felipecrv Mind giving this a quick skim over? I'm not sure whether this is at the R or C++ layer, but one of the places in the codebase when I grep for the
array cannot contain more thanerror was updated in #35345 which appears to be have merged after this error appeared, so I figure you might be more familar with that area of the codebase than us, even if it's not related to this?felipecrv commentedon Feb 6, 2024
@thisisnic sure. I'm going to take a look now.
felipecrv commentedon Feb 6, 2024
log(2147483646 + 2, 2)is 31, so this is a check coming fromBaseBinaryBuilder<T>which usessizeof<offset_type>in thememory_limit()method.FixedSizeBinaryBuildercan produce the same message, but it always usesint64_tas these arrays don't need an offsets buffer.The regular string builder is based on
BaseBinaryBuilder<T>and it uses 32-bits for the offsets array, so it requires all the concatenated strings to be addressable with 31 bits (~2GB). But the bug report says the column type isLargeStringwhich uses 64-bit offsets! It shouldn't be a problem.Digging into the Parquet reader code, I find...
...leading to a commit from November:
This is from PR #8632 that fixed Issue #26405 which is about writing LargeString into Arrow, but doesn't fix the reading them back part. I suppose the value in this is that C++/R/Python scripts can produce files that the Java Parquet reader can read without problems.
Next steps:
thisisnic commentedon Feb 6, 2024
Thanks for figuring that one out @felipecrv. I've updated the title to reflect that it's a C++ bug, though don't have the capacity to implement the fix myself.
[-][R] read_parquet error - unable to read in large parquet files that previously opened[/-][+][C++] read_parquet error - unable to read in large parquet files that previously opened[/+][-][C++] read_parquet error - unable to read in large parquet files that previously opened[/-][+][C++] Parquet reader is unable to read LargeString columns[/+]mapleFU commentedon Feb 6, 2024
Do you mean 14.0.2 or other? I did a bug fix here on 14.0.2 ( #38784 ), not sure whether this is related
thisisnic commentedon Feb 6, 2024
It could be related, we haven't been able to release 14.0.2 to CRAN, so it'll be 14.0.0.2, which is 14.0.0 but with some R patches.
8 remaining items
mapleFU commentedon Jun 13, 2024
Sorry for late replying, @nicki-dese Have this problem solved with later R or 14.0.2? If not I'll dive into it now
raulcd commentedon Jun 26, 2024
Is this still considered a blocker for the release?
@thisisnic @assignUser @jonkeane
jonkeane commentedon Jun 26, 2024
We should get @mapleFU and @felipecrv input on this — from reading there's an issue in our C++ parquet reader that is causing this. From reading #41104 and #35825 there's a proposal but it doesn't look close enough to finished that it'll make it in the release (please, do correct me if I'm wrong on that!)
I'm going to remove the blocker label so we don't prevent this release, though we absolutely should fix this issue in the parquet reader
mapleFU commentedon Jun 26, 2024
Personally I think this is likely to be solved in 14.0.2 . The issue is that it can be read in 13.0, so it could handled by #38784 . But I didn't got enough input on this :-(
jonkeane commentedon Jun 26, 2024
Thanks for the update! Yeah, I tried a gentle nudge there too, let's see if that goes forward for next release (17.0.0)?
mapleFU commentedon Jun 26, 2024
I think large-column can be read now, and for next release we may support read large dictionary. If there're any reproduce-able bug just report and let me fix it
raulcd commentedon Jun 26, 2024
ok, so I understand that this should be fixed for 17.0.0 and no further action is required. Should we close this issue then? If we want to maintain the issue opened, should we remove the blocker label and the 17.0.0 milestone?
raulcd commentedon Jun 26, 2024
Thansk @mapleFU @jonkeane !
jonkeane commentedon Jun 26, 2024
Oh, sorry, I misunderstood this! That's great that this is fixed for strings just not dictionaries. Do we have a test for this somewhere in the C++ suite that confirms this? I could probably add one in R too, but that's a bit higher and superfluous if we already have a C++ one.
mapleFU commentedon Jun 26, 2024
You're right I think I'd better adding a testcase for this 🤔 The read large column logic is tested but I guess this behavior is left behind. I'm busy in workdays these days. I'll try construct a unittest this weekend
Technically, Parquet has the limit below:
but when read a batch or a table, it could be greater, so when reading string, parquet reader would use a group of api to "split to small chunks" using multiple
BinaryBuilder/StringBuilder, during building, once incoming string can make the buffer exceeds 2GB, reader would switch to a new Builder. Finally, reader casting them to LargeString/LargeBinary later. I think this logic is already tested, but maybe some test for corner case should be added.felipecrv commentedon Jun 26, 2024
@mapleFU yeah. The issue stems from offsets of
StringArraybeing cumulative.I think a better strategy to support
LargeStringArraywould be readingStringViewfrom Parquet instead ofStringArrayand then casting fromStringViewto eitherStringArrayorLargeStringArrayat the end.The
StringViewarrays can use a variadic number of buffers, so before cumulative offsets reach 2GB, you can start building up anotherBuffer.I have code that casts string-views on my machine (PR soon). A
StringViewArraytoStringArraycast can be made very efficient if only one variadicBufferwas used — something that we can try to maximize in the Parquet reader.nicki-dese commentedon Jun 26, 2024
Apologies for the delay in replying @mapleFU, I've just tested arrow 16.1.0 and read_parquet successfully read in a previously problematic file with large strings - so the bug appears fixed from my end.
assignUser commentedon Jul 18, 2024
As we have a few follow up issues for the underlying problems and the user facing issues is fixed I'll close this.