laserninja commented on code in PR #10641:
URL: https://github.com/apache/gravitino/pull/10641#discussion_r3025827849


##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergRESTUtils.java:
##########
@@ -39,15 +43,100 @@
 import org.apache.iceberg.catalog.Namespace;
 import org.apache.iceberg.catalog.TableIdentifier;
 import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.rest.responses.LoadTableResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class IcebergRESTUtils {
 
+  private static final Logger LOG = 
LoggerFactory.getLogger(IcebergRESTUtils.class);
+
+  public static final String DEFAULT_SNAPSHOTS = "all";
+
   private IcebergRESTUtils() {}
 
   public static <T> Response ok(T t) {
     return 
Response.status(Response.Status.OK).entity(t).type(MediaType.APPLICATION_JSON).build();
   }
 
+  /**
+   * Builds an OK response with the ETag header derived from the table 
metadata location. Uses the
+   * default snapshots value to ensure ETags from create/update/register are 
consistent with the
+   * default loadTable endpoint.
+   *
+   * @param loadTableResponse the table response to include in the body
+   * @return a Response with ETag header set
+   */
+  public static Response buildResponseWithETag(LoadTableResponse 
loadTableResponse) {
+    EntityTag etag =
+        generateETag(loadTableResponse.tableMetadata().metadataFileLocation(), 
DEFAULT_SNAPSHOTS);
+    return buildResponseWithETag(loadTableResponse, etag);
+  }
+
+  /**
+   * Builds an OK response with the given ETag header.
+   *
+   * @param loadTableResponse the table response to include in the body
+   * @param etag the pre-computed ETag, may be null
+   * @return a Response with ETag header set if etag is non-null
+   */
+  public static Response buildResponseWithETag(
+      LoadTableResponse loadTableResponse, EntityTag etag) {
+    Response.ResponseBuilder responseBuilder =
+        Response.ok(loadTableResponse, MediaType.APPLICATION_JSON_TYPE);
+    if (etag != null) {
+      responseBuilder.tag(etag);
+    }
+    return responseBuilder.build();
+  }
+
+  /**
+   * Generates an ETag based on the table metadata file location. The ETag is 
a SHA-256 hash of the
+   * metadata location, which changes whenever the table metadata is updated.
+   *
+   * @param metadataLocation the metadata file location
+   * @return the generated ETag, or null if generation fails
+   */
+  public static EntityTag generateETag(String metadataLocation) {
+    return generateETag(metadataLocation, null);

Review Comment:
   done



-- 
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]

Reply via email to