Skip to content

feat: Making From<ConfigFileDecryptionProperties/ConfigFileEncryptionProperties> conversions fallible with TryFrom#21985

Open
Soham-Bhattacharjee-work wants to merge 9 commits intoapache:mainfrom
Soham-Bhattacharjee-work:from-to-try_from-for-ConfigEncryptionDecryption
Open

feat: Making From<ConfigFileDecryptionProperties/ConfigFileEncryptionProperties> conversions fallible with TryFrom#21985
Soham-Bhattacharjee-work wants to merge 9 commits intoapache:mainfrom
Soham-Bhattacharjee-work:from-to-try_from-for-ConfigEncryptionDecryption

Conversation

@Soham-Bhattacharjee-work
Copy link
Copy Markdown

@Soham-Bhattacharjee-work Soham-Bhattacharjee-work commented May 2, 2026

Which issue does this PR close?

Rationale for this change

The conversions from ConfigFileDecryptionProperties to FileDecryptionProperties and from ConfigFileEncryptionProperties to FileEncryptionProperties currently use From, but the implementations contain several unwrap() and expect() calls which can cause panics for invalid or wrong inputs. Instead of panics we can gracefully return DataFusionError::Confoguration errors.

What changes are included in this PR?

impl From<ConfigFileEncryptionProperties> for FileEncryptionProperties

becomes

impl TryFrom<ConfigFileEncryptionProperties> for FileEncryptionProperties

Similarly

impl From<ConfigFileDecryptionProperties> for FileDecryptionProperties

becomes

impl TryFrom<ConfigFileDecryptionProperties> for FileDecryptionProperties

These are header changes with accompanied implementation changes

Are these changes tested?

Yes tests are added in datafusion/common/src/config.rs

Are there any user-facing changes?

Yes this is an user facing change. And upgradation guide is added in 54.0.0.md

@github-actions github-actions Bot added common Related to common crate datasource Changes to the datasource crate labels May 2, 2026
@Soham-Bhattacharjee-work Soham-Bhattacharjee-work changed the title Making From<ConfigFileDecryptionProperties/ConfigFileEncryptionProperties> conversions fallible with TryFrom feat: Making From<ConfigFileDecryptionProperties/ConfigFileEncryptionProperties> conversions fallible with TryFrom May 2, 2026
Copy link
Copy Markdown
Contributor

@kumarUjjawal kumarUjjawal left a comment

Choose a reason for hiding this comment

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

Thank you @Soham-Bhattacharjee-work I have left some comments, also can you update the pr body that this is user facing change since it is API breaking

Comment thread datafusion/common/src/config.rs Outdated
let encryption_key = hex::decode(&encryption_props.column_key_as_hex)
.expect("Invalid column encryption key");
.map_err(|e| {
DataFusionError::Configuration(format!("Unable to decode hex encryption key metadata for column {column_name}: {e}"))
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.

message says "encryption key metadata", but this is decoding the actual column encryption key. Please change it.

Copy link
Copy Markdown
Author

@Soham-Bhattacharjee-work Soham-Bhattacharjee-work May 3, 2026

Choose a reason for hiding this comment

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

Oops sorry ! 😄

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed

#[cfg(feature = "parquet_encryption")]
impl From<ConfigFileEncryptionProperties> for FileEncryptionProperties {
fn from(val: ConfigFileEncryptionProperties) -> Self {
impl TryFrom<ConfigFileEncryptionProperties> for FileEncryptionProperties {
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.

we need entry in upgrade guide.

Copy link
Copy Markdown
Author

@Soham-Bhattacharjee-work Soham-Bhattacharjee-work May 3, 2026

Choose a reason for hiding this comment

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

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 3, 2026
Copy link
Copy Markdown
Contributor

@adamreeve adamreeve left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up @Soham-Bhattacharjee-work

Comment thread datafusion/common/src/config.rs Outdated
let mut column_keys: Vec<Vec<u8>> = Vec::new();

for (col_name, decryption_properties) in val.column_decryption_properties.iter() {
let column_key_as_hex = hex::decode(&decryption_properties.column_key_as_hex).map_err(|e| {
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.

column_key_as_hex has been decoded from hex, so this should probably just be called column_key.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done


**Before:**

```rust,ignore
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 upgrade guide section feels too long for the actual API change. The migration is just replacing from/into with try_from/try_into and handling the Result. Could we shorten this to a small before/after snippet instead of showing the full encryption and decryption config setup? Take inspiration from the work just above for the similar change.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

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

Labels

common Related to common crate datasource Changes to the datasource crate documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make From<ConfigFileDecryptionProperties>/ConfigFileEncryptionProperties conversions fallible (TryFrom)

3 participants