Skip to content

feat(encryption): [13/N] Write encrypted Parquet data files - #4328

Merged
kevinjqliu merged 4 commits into
apache:mainfrom
xanderbailey:xb/encryption-write-parquet
Nov 13, 2026
Merged

kevinjqliu merged 4 commits into
apache:mainfrom
xanderbailey:xb/encryption-write-parquet

Conversation

@xanderbailey

Copy link
Copy Markdown
Contributor

Working towards #3222

Rationale for this change

First write-side PR: data files of an encrypted table are written with Parquet Modular Encryption.

  • Each data file gets its own key and AAD prefix, recorded as the DataFile's key_metadata.
  • Like Java, the AAD prefix isn't stored in the file.
  • Needs pyarrow >= 25, and raises on older versions rather than writing plaintext.

Commits to v3 tables still fail at the manifest writer, so encrypted manifests come next once #3624 lands.

Are these changes tested?

Yes, write_file on an encrypted table writes encrypted files that read back through a scan. I also checked iceberg-rust can read one.

Are there any user-facing changes?

No.

Data files of a table with encryption.key-id are written with Parquet modular
encryption, using a fresh key and AAD prefix per file, and the key metadata is
recorded on the DataFile. Like Java, the AAD prefix is not stored in the file.
Comment thread pyiceberg/io/fileformat.py Resolved
Keeps plaintext writes working with FileFormatModel implementations that
predate the key_metadata argument.
@xanderbailey
xanderbailey marked this pull request as ready for review November 10, 2026 23:43
if (table_key_id := metadata.properties.get(TableProperties.ENCRYPTION_KEY_ID)) is None:
return None

if not isinstance(metadata, TableMetadataV3):

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.

nit: not related to this pr, but generally i think we should compare using "version >= 3" instead of isinstance

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread pyiceberg/io/fileformat.py Resolved
Comment thread pyiceberg/io/pyarrow.py Outdated
self._fos: OutputStream | None = None
self._parquet_writer_kwargs = _get_parquet_writer_kwargs(properties)
if key_metadata is not None:
self._parquet_writer_kwargs["encryption_properties"] = _parquet_encryption_properties(key_metadata)

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.

Comment thread pyiceberg/io/pyarrow.py Resolved
kevinjqliu and others added 2 commits November 13, 2026 11:50
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@kevinjqliu kevinjqliu 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.

LGTM thanks!

i made 2 commits (dba6ed9 and ad8eb51) to pass key_metadata as it down the stack, even if its None. I think this is cleaner than checking for None at each level. Ultimately pyarrow handles the None value 😄

Comment thread pyiceberg/io/pyarrow.py
Comment on lines +1179 to +1182
def _parquet_encryption_properties(key_metadata: StandardKeyMetadata | None) -> pq.FileEncryptionProperties | None:
if key_metadata is None:
return None

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.

this is a nit change, i prefer to keep the logic inside _parquet_encryption_properties itself and simplify ParquetFormatWriter.__init__

@kevinjqliu
kevinjqliu enabled auto-merge November 13, 2026 19:59
@kevinjqliu

Copy link
Copy Markdown
Contributor

Thanks @xanderbailey feels like we are very close to E2E read/write of encrypted tables 😄

@xanderbailey

Copy link
Copy Markdown
Contributor Author

Very nice improvements, thanks Kevin

@kevinjqliu
kevinjqliu added this pull request to the merge queue Nov 13, 2026
Merged via the queue into apache:main with commit 581e716 Nov 13, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants