szehon-ho commented on code in PR #4456:
URL: https://github.com/apache/iceberg/pull/4456#discussion_r845634305


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -402,9 +411,43 @@ private void setHmsTableParameters(String 
newMetadataLocation, Table tbl, TableM
       parameters.put(StatsSetupConst.TOTAL_SIZE, 
summary.get(SnapshotSummary.TOTAL_FILE_SIZE_PROP));
     }
 
+    setSnapshotStats(metadata, parameters);
+
     tbl.setParameters(parameters);
   }
 
+  private void setSnapshotStats(TableMetadata metadata, Map<String, String> 
parameters) {
+    Snapshot currentSnapshot = metadata.currentSnapshot();
+    if (currentSnapshot != null) {
+      parameters.put(TableProperties.CURRENT_SNAPSHOT_ID, 
String.valueOf(currentSnapshot.snapshotId()));
+      parameters.put(TableProperties.CURRENT_SNAPSHOT_TIMESTAMP, 
String.valueOf(currentSnapshot.timestampMillis()));
+      setSnapshotSummary(parameters, currentSnapshot);
+    } else {
+      parameters.remove(TableProperties.CURRENT_SNAPSHOT_ID);
+      parameters.remove(TableProperties.CURRENT_SNAPSHOT_TIMESTAMP);
+      parameters.remove(TableProperties.CURRENT_SNAPSHOT_SUMMARY);
+    }
+
+    parameters.put(TableProperties.SNAPSHOT_COUNT, 
String.valueOf(metadata.snapshots().size()));
+  }
+
+  @VisibleForTesting
+  void setSnapshotSummary(Map<String, String> parameters, Snapshot 
currentSnapshot) {
+    try {
+      String summary = 
JsonUtil.mapper().writeValueAsString(currentSnapshot.summary());
+      if (summary.length() <= maxHiveTablePropertySize) {
+        parameters.put(TableProperties.CURRENT_SNAPSHOT_SUMMARY, summary);
+      } else {
+        parameters.remove(TableProperties.CURRENT_SNAPSHOT_SUMMARY);

Review Comment:
   Optional: we can actually put the parameters.remove() for all the properties 
above the parameters.put(), here we are doing the remove three times.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to