You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++][Parquet] RleDecoder::Get fails to return false on end for some bit widths #46094
Describe the bug, including details regarding any error messages, version, and platform.
On the current main branch, the specified behavior of arrow::util::RleDecoder::Get is to return false if there are no more elements. However, this behavior doesn't work for some bit widths. This failing test case illustrates this: lesterfan@2722055.
I added some logging to the above test case for the original/decoded vector values and lengths below. The RleDecoder seems to be reading some additional values at the end of the buffer for this particular case with bit_width = 17.
I'm happy to take a deeper look in the code and try to find a fix when I'm free! Though it may be more efficient if someone with more context looks as well as this part of the codebase is quite scary 😅
Looking into this some more, one strange thing is that the attached simple test case (with bit_width = 17 fails on my M1 Macbook Pro but passes on my Intel i9 Windows laptop. I'm able to repro this on both platforms with the following test modification which is a bit more complicated: lesterfan@42931e4.
Since the encoding only supports literal runs with lengths that are a multiple of 8, the RleEncoder sometimes has to pad the last literal run with zeros. This means that the number of encoded values can't be determined from just looking at the run-length encoded data since the encoding does not differentiate between real values and padding values. So calling RleDecoder::Get until it returns false might result in extra zeros from the padding.
The solution is to separately keep track of the number of values and only call Get that many times.
This makes sense; thank you! So in summary, the way that the RleEncoder/RleDecoder are implemented is that literal runs will always be padded to the nearest multiple of 8 to ensure byte alignment. From the decoder's perspective, there's no way to distinguish between a "real" value and one of these padded values. Therefore, it's up to the caller of the RleEncoder/RleDecoder to keep track of how many "real" values they want. In practice, this is done by the Parquet page RecordReader as mentioned by @mapleFU, but in my test I was bypassing this.
Given this, I'm going to close the issue. I think the following docstring could be more clear here, but this sounds largely like a user error from my end:
/// Gets the next value. Returns false if there are no more.
template <typename T>
bool Get(T* val);
Activity
mapleFU commentedon Apr 10, 2025
I haven't checkout this carefully yet, I'll take a round tomorrow
lesterfan commentedon Apr 10, 2025
Thank you for the help!
lesterfan commentedon Apr 13, 2025
Looking into this some more, one strange thing is that the attached simple test case (with
bit_width = 17fails on my M1 Macbook Pro but passes on my Intel i9 Windows laptop. I'm able to repro this on both platforms with the following test modification which is a bit more complicated: lesterfan@42931e4.hadrian-reppas commentedon Jun 20, 2025
Since the encoding only supports literal runs with lengths that are a multiple of 8, the
RleEncodersometimes has to pad the last literal run with zeros. This means that the number of encoded values can't be determined from just looking at the run-length encoded data since the encoding does not differentiate between real values and padding values. So callingRleDecoder::Getuntil it returns false might result in extra zeros from the padding.The solution is to separately keep track of the number of values and only call
Getthat many times.mapleFU commentedon Jun 20, 2025
Actually Parquet Page
RecordReaderwould track the num of values🤔lesterfan commentedon Jun 20, 2025
This makes sense; thank you! So in summary, the way that the
RleEncoder/RleDecoderare implemented is that literal runs will always be padded to the nearest multiple of 8 to ensure byte alignment. From the decoder's perspective, there's no way to distinguish between a "real" value and one of these padded values. Therefore, it's up to the caller of the RleEncoder/RleDecoder to keep track of how many "real" values they want. In practice, this is done by the Parquet pageRecordReaderas mentioned by @mapleFU, but in my test I was bypassing this.Given this, I'm going to close the issue. I think the following docstring could be more clear here, but this sounds largely like a user error from my end:
kou commentedon Jun 20, 2025
We'll improve docstring.
GH-46094: [C++][Docs] Add note to RleDecoder::Get's doc comment (#46874)
kou commentedon Jun 23, 2025
Issue resolved by pull request 46874
#46874