You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/07/14 16:54:39 UTC

[GitHub] [iceberg] kbendick commented on a diff in pull request #5275: Write metadata-location instead of metadataLocation

kbendick commented on code in PR #5275:
URL: https://github.com/apache/iceberg/pull/5275#discussion_r921347956


##########
core/src/main/java/org/apache/iceberg/rest/responses/LoadTableResponse.java:
##########
@@ -37,6 +42,56 @@
  */
 public class LoadTableResponse implements RESTResponse {
 
+  private static final String METADATA_LOCATION = "metadata-location";
+  private static final String METADATA = "metadata";
+  private static final String CONFIG = "config";
+
+  public static void toJson(LoadTableResponse loadTable, JsonGenerator generator) throws IOException {
+    generator.writeStartObject();
+
+    generator.writeStringField(METADATA_LOCATION, loadTable.metadataLocation);
+
+    generator.writeFieldName(METADATA);
+    TableMetadataParser.toJson(loadTable.metadata, generator);
+
+    generator.writeObjectFieldStart(CONFIG);
+    for (Map.Entry<String, String> keyValue : loadTable.config.entrySet()) {
+      generator.writeStringField(keyValue.getKey(), keyValue.getValue());

Review Comment:
   Do we need a null check here? I believe this throws if `keyValue.getValue()` is null.



##########
core/src/main/java/org/apache/iceberg/rest/responses/LoadTableResponse.java:
##########
@@ -37,6 +42,56 @@
  */
 public class LoadTableResponse implements RESTResponse {
 
+  private static final String METADATA_LOCATION = "metadata-location";
+  private static final String METADATA = "metadata";
+  private static final String CONFIG = "config";
+
+  public static void toJson(LoadTableResponse loadTable, JsonGenerator generator) throws IOException {
+    generator.writeStartObject();
+
+    generator.writeStringField(METADATA_LOCATION, loadTable.metadataLocation);
+
+    generator.writeFieldName(METADATA);
+    TableMetadataParser.toJson(loadTable.metadata, generator);
+
+    generator.writeObjectFieldStart(CONFIG);
+    for (Map.Entry<String, String> keyValue : loadTable.config.entrySet()) {
+      generator.writeStringField(keyValue.getKey(), keyValue.getValue());
+    }
+    generator.writeEndObject();
+
+    generator.writeEndObject();
+  }
+
+  public static LoadTableResponse fromJson(JsonNode node) {
+    Preconditions.checkArgument(node.isObject(),
+            "Cannot parse table response from a non-object: %s", node);
+
+    String metadataLocation = null;
+    JsonNode  metadataLocationNode = node.get(METADATA_LOCATION);
+    if(metadataLocationNode != null) {
+      metadataLocation = metadataLocationNode.asText();
+    }

Review Comment:
   You can use `String metadataLocation = JsonUtil.getStringOrNull(METADATA_LOCATION, node)` for convenience here.



##########
core/src/main/java/org/apache/iceberg/rest/responses/LoadTableResponse.java:
##########
@@ -89,8 +144,15 @@ public static class Builder {
     private Builder() {
     }
 
+      public Builder withMetadataLocation(String metadataLocation) {
+          this.metadataLocation = metadataLocation;
+          return this;
+      }

Review Comment:
   +1 to this. I find that sometimes, the `TableMetadata` that gets passed has `null` for `metadataLocation`, in which case we need to use the `TableMetadataBuilder` to add it which isn't very convenient.  👍 
   
   



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org