Skip to content
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

Parquet-java sometimes produces 0-size compressed data in data page v2 #3122

Open
mapleFU opened this issue Jan 15, 2025 · 5 comments
Open

Comments

@mapleFU
Copy link
Member

mapleFU commented Jan 15, 2025

Describe the bug

See:

  1. GH-31992: [C++][Parquet] Handling the special case when DataPageV2 values buffer is empty arrow#45252 (comment)
  2. File: https://github.com/user-attachments/files/18292070/snappy_bug.parquet.gz

V2 data pages do not compress def/rep levels, only the values. In the (not uncommon) case where all data is null, Parquet-java may write 0 compressed bytes for a 0-size decompressed data. However, a 0-size compressed buffer is not a valid input for compressors. The data page then fails decompressing in the C++ and Rust implementations.

Component(s)

Core

@pitrou
Copy link
Member

pitrou commented Jan 15, 2025

It's not an enhancement, it's a bug in Parquet-java.

@pitrou pitrou changed the title Parquet: a 0-size buffer compressed to a 1-size buffer using Snappy. Parquet-java sometimes produces 0-size compressed data in data page v2 Jan 15, 2025
@ConeyLiu
Copy link
Contributor

Let me take a look at this. What the compressed bytes size is written out on the C++ side for this case?

@pitrou
Copy link
Member

pitrou commented Jan 24, 2025

I could try directly with Arrow C++, but Python tells me it should be a single 0 byte for Snappy:

>>> snappy.compress(b"")
b'\x00'

And, of course, that depends on the compression algorithm. See for example Zstd:

>>> zstd.compress(b"")
b'(\xb5/\xfd \x00\x01\x00\x00'
>>> zstd.compress(b"").hex()
'28b52ffd2000010000'

@pitrou
Copy link
Member

pitrou commented Jan 24, 2025

But I think that's irrelevant anyway. What you should do if there are 0 uncompressed bytes is simply to set is_compressed to false in the DataPageV2 header, and write 0 uncompressed bytes:
https://github.com/apache/parquet-format/blob/a498aa9a377edcdbc5da802cf9f1763a2e409411/src/main/thrift/parquet.thrift#L664-L669

@ConeyLiu
Copy link
Contributor

@pitrou, thanks for the background information and suggestions you provided. I will fix it after the Chinese New Year holiday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants