Skip to content

Conversation

@smaheshwar-pltr
Copy link
Contributor

Minor clean-ups to Hive encryption integration that arose from #13225

cc @ggershinsky @huaxingao

@github-actions github-actions bot added the hive label Nov 22, 2025
if (keyManagementClient == null) {
throw new RuntimeException(
"Cant create encryption manager, because key management client is not set");
"Cannot create encryption manager without a key management client");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a nit, matching the "Cannot" language used elsewhere. (Not strongly opinionated though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could take this further with maybe:

throw new RuntimeException(
    "Cannot create encryption manager without a key management client. Consider setting the '"
        + CatalogProperties.ENCRYPTION_KMS_IMPL + "' catalog property.");

However, this might be a bit premature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could also throw a different exception class here

Copy link
Contributor

Choose a reason for hiding this comment

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

IllegalArgs or a Precondition prompting the key to be set sounds reasonable to me

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to use IllegalArgumentException or Preconditions check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks all, have made the change. You now get:

java.lang.IllegalArgumentException: Cannot create encryption manager without a key management client. Consider setting the 'encryption.kms-impl' catalog property
	at org.apache.iceberg.relocated.com.google.common.base.Preconditions.checkArgument(Preconditions.java:217)

encryptionProperties.put(
TableProperties.ENCRYPTION_DEK_LENGTH, String.valueOf(encryptionDekLength));
Map<String, String> encryptionProperties =
ImmutableMap.of(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In #13225, I felt like ImmutableMap.of would be more natural here


if (removedProps.contains(TableProperties.ENCRYPTION_TABLE_KEY)) {
throw new RuntimeException("Cannot remove key in encrypted table");
throw new IllegalArgumentException(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This follows the discussion #13225 (comment). To me, IllegalArgumentException makes sense

@smaheshwar-pltr smaheshwar-pltr changed the title Hive encryption clean-ups Hive encryption nits Nov 22, 2025
@github-actions github-actions bot added the spark label Nov 22, 2025
assertThatThrownBy(
() -> sql("ALTER TABLE %s UNSET TBLPROPERTIES (`encryption.key-id`)", tableName))
.hasMessageContaining("Cannot remove key in encrypted table");
.hasMessageContaining("Cannot remove encryption key ID from an encrypted table");
Copy link
Contributor

Choose a reason for hiding this comment

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

can we check the execption class too ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! be2a7e5

if (keyManagementClient == null) {
throw new RuntimeException(
"Cant create encryption manager, because key management client is not set");
"Cannot create encryption manager without a key management client");
Copy link
Contributor

Choose a reason for hiding this comment

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

IllegalArgs or a Precondition prompting the key to be set sounds reasonable to me

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants