Skip to content

Commit 2316c8e

Browse files
Address review comments.
Co-authored-by: smaheshwar-pltr <[email protected] >
1 parent 060ee33 commit 2316c8e

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,18 @@ the table key parameter (along with existing snapshots) in the file, making the
194194
refreshFromMetadataLocation(metadataLocation, metadataRefreshMaxRetries);
195195

196196
if (tableKeyIdFromHMS != null) {
197+
checkEncryptionProperties(tableKeyIdFromHMS, dekLengthFromHMS);
198+
197199
tableKeyId = tableKeyIdFromHMS;
198200
encryptionDekLength =
199201
(dekLengthFromHMS != null)
200202
? Integer.parseInt(dekLengthFromHMS)
201203
: TableProperties.ENCRYPTION_DEK_LENGTH_DEFAULT;
202204

203-
checkEncryptionProperties(tableKeyIdFromHMS, dekLengthFromHMS);
204205
encryptedKeysFromMetadata = current().encryptionKeys();
206+
// Force re-creation of encryption manager with updated keys
207+
encryptingFileIO = null;
208+
encryptionManager = null;
205209
}
206210
}
207211

@@ -212,11 +216,12 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
212216
encryptionPropsFromMetadata(metadata.properties());
213217

214218
String newMetadataLocation;
215-
if (encryption() instanceof StandardEncryptionManager) {
219+
EncryptionManager encryptionManager = encryption();
220+
if (encryptionManager instanceof StandardEncryptionManager) {
216221
// Add new encryption keys to the metadata
217222
TableMetadata.Builder builder = TableMetadata.buildFrom(metadata);
218223
for (Map.Entry<String, EncryptedKey> entry :
219-
EncryptionUtil.encryptionKeys(encryption()).entrySet()) {
224+
EncryptionUtil.encryptionKeys(encryptionManager).entrySet()) {
220225
builder.addEncryptionKey(entry.getValue());
221226
}
222227

spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/sql/TestTableEncryption.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
import java.util.Map;
3131
import java.util.stream.Collectors;
3232
import org.apache.iceberg.CatalogProperties;
33+
import org.apache.iceberg.DataFile;
34+
import org.apache.iceberg.FileScanTask;
3335
import org.apache.iceberg.MetadataTableType;
3436
import org.apache.iceberg.Parameters;
3537
import org.apache.iceberg.Schema;
38+
import org.apache.iceberg.Table;
3639
import org.apache.iceberg.encryption.Ciphers;
3740
import org.apache.iceberg.encryption.UnitestKMS;
3841
import org.apache.iceberg.io.InputFile;
@@ -92,6 +95,25 @@ public void testSelect() {
9295
assertEquals("Should return all expected rows", expected, sql("SELECT * FROM %s", tableName));
9396
}
9497

98+
private static List<DataFile> currentDataFiles(Table table) {
99+
return Streams.stream(table.newScan().planFiles())
100+
.map(FileScanTask::file)
101+
.collect(Collectors.toList());
102+
}
103+
104+
@TestTemplate
105+
public void testRefresh() {
106+
catalog.initialize(catalogName, catalogConfig);
107+
Table table = catalog.loadTable(tableIdent);
108+
109+
assertThat(currentDataFiles(table)).isNotEmpty();
110+
111+
sql("INSERT INTO %s VALUES (4, 'd', 4.0), (5, 'e', 5.0), (6, 'f', float('NaN'))", tableName);
112+
113+
table.refresh();
114+
assertThat(currentDataFiles(table)).isNotEmpty();
115+
}
116+
95117
@TestTemplate
96118
public void testInsertAndDelete() {
97119
sql("INSERT INTO %s VALUES (4, 'd', 4.0), (5, 'e', 5.0), (6, 'f', float('NaN'))", tableName);

0 commit comments

Comments
 (0)