Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.LocationProvider;
import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.apache.iceberg.util.PropertyUtil;
import org.apache.thrift.TException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -148,13 +148,15 @@ public EncryptionManager encryption() {
if (tableKeyId != null) {
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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)

}

Map<String, String> encryptionProperties = Maps.newHashMap();
encryptionProperties.put(TableProperties.ENCRYPTION_TABLE_KEY, tableKeyId);
encryptionProperties.put(
TableProperties.ENCRYPTION_DEK_LENGTH, String.valueOf(encryptionDekLength));
Map<String, String> encryptionProperties =
ImmutableMap.of(

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.

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

TableProperties.ENCRYPTION_TABLE_KEY,
tableKeyId,
TableProperties.ENCRYPTION_DEK_LENGTH,
String.valueOf(encryptionDekLength));

List<EncryptedKey> keys = Lists.newLinkedList();
encryptedKeysFromMetadata.ifPresent(keys::addAll);
Expand Down Expand Up @@ -321,7 +323,8 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
}

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

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.

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

"Cannot remove encryption key ID from an encrypted table");
}

HMSTablePropertyHelper.updateHmsTableForIcebergTable(
Expand Down
Loading