You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "geruh (via GitHub)" <gi...@apache.org> on 2025/11/27 08:01:04 UTC

[PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

geruh opened a new pull request, #14702:
URL: https://github.com/apache/iceberg/pull/14702

   ## Summary
   
   This PR aligns the `ContentFile` partition field JSON serialization in `ContentFileParser` with the REST spec, that specifies partition data as an ordered array of values.
   
   The REST spec uses an array of primitives to represent partitions, and that was discussed here in https://github.com/apache/iceberg/pull/9717#discussion_r1495010775 when the spec was designed. However, while testing it looks like  `ContentFileParser` hasn't had the updates to reflect this yet and was using `SingleValueParser`, which produces a field ID map like `{"1000": 1}` instead of an array `[1]`.
   
   ## Testing
   
   **Serialize a partitioned data file:**
   ```
   > ContentFileParser.toJson(dataFile, spec)
   
   {"spec-id":0,"content":"DATA","file-path":"data.parquet", "file-format":"PARQUET","partition":[1],"file-size-in-bytes":10, "record-count":1,"sort-order-id":0....}
   ```
   
   **Unpartitioned table**
   ```
   {"partition":[]}
   ```
   
   **non array:**
   ```
   > ContentFileParser.partitionFromJson({"partition": {"1000": 1}}, specs)
   
     java.lang.IllegalArgumentException: Invalid partition data for content file: non-array...
   ```
   cc: @singhpk234 @amogh-jahagirdar 
   


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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#issuecomment-3603430136

   Thanks @geruh for the PR! Thanks @singhpk234 for the review!


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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2579067538


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,58 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(
+          partitionNode.size() == fields.size(),
+          "Invalid partition data size: expected = %s, actual = %s",
+          fields.size(),
+          partitionNode.size());
+
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+        partitionData.set(pos, partitionValue);
+      }
+    } else if (partitionNode.isObject()) {
+      // Handle partition struct object format, which serializes by field ID and skips
+      // null partition values
+      Preconditions.checkState(
+          partitionNode.size() <= fields.size(),

Review Comment:
   I think it’s hard to draw a line there, only because the "legacy" object form omits null values. This makes it hard to know the difference between something that was intentionally Null and something that we forgot to serialize. for example, `PartitionData("1000": "a", "1001":null)` would serialize to `{"1000": "a"}`.



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2572633645


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,41 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    Preconditions.checkArgument(
+        partitionNode.isArray(),
+        "Invalid partition data for content file: non-array (%s)",
+        partitionNode);

Review Comment:
   Yeah, I agree. I think that's a good call. I think the important part here is for file scan tasks that are sent over the wire, can respect the rest spec, and we could have fallback for Flink. In all new cases, we'll  be strict with what we send out.
   
   I have updated the existing test to reflect the new serialization and added test to reflect the fallback.



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2572924506


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,55 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(
+          partitionNode.size() == fields.size(),
+          "Invalid partition data size: expected = %s, actual = %s",
+          fields.size(),
+          partitionNode.size());
+
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+        partitionData.set(pos, partitionValue);
+      }
+    } else if (partitionNode.isObject()) {
+      // Handle legacy partition object serialization
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        String fieldId = String.valueOf(field.fieldId());
+        if (partitionNode.has(fieldId)) {
+          Object partitionValue =
+              SingleValueParser.fromJson(field.type(), partitionNode.get(fieldId));
+          partitionData.set(pos, partitionValue);
+        }
+      }

Review Comment:
   Yeah I agree, I thought this was a bit more defensive but the original cleans things up. As for the precondition the structlike tracks the schema size so case will pretty much always be true. Furthermore, the parsing is sparse meaning nulls are omitted so I think it would be safer to have it be a <= case. 
   



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2573048777


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,58 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(
+          partitionNode.size() == fields.size(),
+          "Invalid partition data size: expected = %s, actual = %s",
+          fields.size(),
+          partitionNode.size());
+
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+        partitionData.set(pos, partitionValue);
+      }
+    } else if (partitionNode.isObject()) {
+      // Handle partition struct object format, which serializes by field ID and skips
+      // null partition values
+      Preconditions.checkState(
+          partitionNode.size() <= fields.size(),

Review Comment:
   I think we might wanna assert now that what is missing was null ? 



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2572633645


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,41 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    Preconditions.checkArgument(
+        partitionNode.isArray(),
+        "Invalid partition data for content file: non-array (%s)",
+        partitionNode);

Review Comment:
   Yeah, I agree. I think that's a good call. I think the important part here is for file scan tasks that are sent over the wire, can respect the rest spec, and we could have fallback for Flink.



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2583129348


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,58 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);

Review Comment:
   nit: We can use `field.type().javaClass()` here, instead of `Object.class).



##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,58 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(

Review Comment:
   nit: add a comment like this
   ```
   In 1.11 and after, partition data is serialized as an array with just partition field values.
   ```



##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,58 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(
+          partitionNode.size() == fields.size(),
+          "Invalid partition data size: expected = %s, actual = %s",
+          fields.size(),
+          partitionNode.size());
+
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+        partitionData.set(pos, partitionValue);
+      }
+    } else if (partitionNode.isObject()) {
+      // Handle partition struct object format, which serializes by field ID and skips

Review Comment:
   maybe update the comment to clarify when the serialization format changed. e.g.
   ```
   In 1.10 and before, partition data is serialized as a struct with partition field ID and partition field value. Null partition field values are skipped.
   ```



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#issuecomment-3587737590

   IMHO i think we should get this in 1.10.1 if the 1.10.1 is not frozen 
   
   - cc @huaxingao 


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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2572763623


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,55 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(
+          partitionNode.size() == fields.size(),
+          "Invalid partition data size: expected = %s, actual = %s",
+          fields.size(),
+          partitionNode.size());
+
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+        partitionData.set(pos, partitionValue);
+      }
+    } else if (partitionNode.isObject()) {
+      // Handle legacy partition object serialization

Review Comment:
   I believe we need assertion here too ? like elements inside obj  == fields size ? presently it can serialized obj can have more elements than partition fields ? 
   
   make me think we don't have coverage for this, can we please add it ? 



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2570275346


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,41 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    Preconditions.checkArgument(
+        partitionNode.isArray(),
+        "Invalid partition data for content file: non-array (%s)",
+        partitionNode);

Review Comment:
   I believe we need to add a fallback logic here for Flink case for backward compatibility ? 
   considering there may be some state checkpointed per old json which will not be readable https://github.com/apache/iceberg/pull/6934#issue-1599173071



##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,41 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    Preconditions.checkArgument(
+        partitionNode.isArray(),
+        "Invalid partition data for content file: non-array (%s)",
+        partitionNode);
+
+    List<Types.NestedField> fields = partitionType.fields();
+    Preconditions.checkArgument(
+        partitionNode.size() == fields.size(),
+        "Invalid partition data size: expected = %s, actual = %s",
+        fields.size(),
+        partitionNode.size());
+
+    PartitionData partitionData = new PartitionData(partitionType);
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+      partitionData.set(pos, partitionValue);
+    }

Review Comment:
   can we add an UT where there are > 1 partitions and each partition with a different type, to check the order ?



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#issuecomment-3603432349

   @geruh could you cherry-pick the change to 1.10.x?


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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#issuecomment-3605084966

   > IMHO i think we should get this in 1.10.1 if the 1.10.1 is not frozen
   > 
   > cc @huaxingao
   
   @huaxingao  We shouldn't include this in the 1.10.1 patch release. It change the serialization for the file scan task which is checkpointed in Flink state.
   
   @geruh we should also add a note for the 1.11.0 release. When a Flink job upgrade the Iceberg version to 1.11.0, it shouldn't roll back to a lower Iceberg version due to this serialization change.
   
   


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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2572924506


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,55 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(
+          partitionNode.size() == fields.size(),
+          "Invalid partition data size: expected = %s, actual = %s",
+          fields.size(),
+          partitionNode.size());
+
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+        partitionData.set(pos, partitionValue);
+      }
+    } else if (partitionNode.isObject()) {
+      // Handle legacy partition object serialization
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        String fieldId = String.valueOf(field.fieldId());
+        if (partitionNode.has(fieldId)) {
+          Object partitionValue =
+              SingleValueParser.fromJson(field.type(), partitionNode.get(fieldId));
+          partitionData.set(pos, partitionValue);
+        }
+      }

Review Comment:
   Yeah I agree, but the structlike tracks the schema size so we can just follow what the array comparison does
   



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#issuecomment-3599382168

   @geruh Could you please address https://github.com/apache/iceberg/pull/14702#discussion_r2573048777 and then we can merge. 


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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2572924506


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,55 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(
+          partitionNode.size() == fields.size(),
+          "Invalid partition data size: expected = %s, actual = %s",
+          fields.size(),
+          partitionNode.size());
+
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+        partitionData.set(pos, partitionValue);
+      }
+    } else if (partitionNode.isObject()) {
+      // Handle legacy partition object serialization
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        String fieldId = String.valueOf(field.fieldId());
+        if (partitionNode.has(fieldId)) {
+          Object partitionValue =
+              SingleValueParser.fromJson(field.type(), partitionNode.get(fieldId));
+          partitionData.set(pos, partitionValue);
+        }
+      }

Review Comment:
   Yeah I agree, I thought this was a bit more defensive but the original cleans things up. As for the precondition the structlike tracks the schema size so case will pretty much always be true. Furthermore, the parsing is sparse meaning nulls are omitted so I think it would be safer to have it be a <= case. 
   
   https://github.com/apache/iceberg/blob/3a9e0a68bfd6c110783a370bd864b90ab25aa9a6/core/src/main/java/org/apache/iceberg/DefaultValueParser.java#L400-L404
   



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2570275346


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,41 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    Preconditions.checkArgument(
+        partitionNode.isArray(),
+        "Invalid partition data for content file: non-array (%s)",
+        partitionNode);

Review Comment:
   I believe we need to add a fallback logic here for Flink case for backward compatibility ? 
   considering there may be some state checkpointed per old json which will not be readable https://github.com/apache/iceberg/pull/6934#issue-1599173071 contentFileParser class has been there since iceberg 1.4.0



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2572768631


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,55 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    List<Types.NestedField> fields = partitionType.fields();
+    PartitionData partitionData = new PartitionData(partitionType);
+
+    if (partitionNode.isArray()) {
+      Preconditions.checkArgument(
+          partitionNode.size() == fields.size(),
+          "Invalid partition data size: expected = %s, actual = %s",
+          fields.size(),
+          partitionNode.size());
+
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        Object partitionValue = SingleValueParser.fromJson(field.type(), partitionNode.get(pos));
+        partitionData.set(pos, partitionValue);
+      }
+    } else if (partitionNode.isObject()) {
+      // Handle legacy partition object serialization
+      for (int pos = 0; pos < fields.size(); ++pos) {
+        Types.NestedField field = fields.get(pos);
+        String fieldId = String.valueOf(field.fieldId());
+        if (partitionNode.has(fieldId)) {
+          Object partitionValue =
+              SingleValueParser.fromJson(field.type(), partitionNode.get(fieldId));
+          partitionData.set(pos, partitionValue);
+        }
+      }

Review Comment:
   minor: Also i would recommend just keeping the existing impl for this scenario wdyt 
   
   ```
         StructLike structLike =
             (StructLike) SingleValueParser.fromJson(spec.partitionType(), jsonNode.get(PARTITION));
         Preconditions.checkState(
             partitionData.size() == structLike.size(),
             "Invalid partition data size: expected = %s, actual = %s",
             partitionData.size(),
             structLike.size());
         for (int pos = 0; pos < partitionData.size(); ++pos) {
           Class<?> javaClass = spec.partitionType().fields().get(pos).type().typeId().javaClass();
           partitionData.set(pos, structLike.get(pos, javaClass));
         }
   ```



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


Re: [PR] Core: Align ContentFile partition JSON with REST spec [iceberg]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #14702:
URL: https://github.com/apache/iceberg/pull/14702#discussion_r2572633645


##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -301,4 +291,41 @@ private static Metrics metricsFromJson(JsonNode jsonNode) {
         lowerBounds,
         upperBounds);
   }
+
+  private static void partitionToJson(
+      Types.StructType partitionType, StructLike partitionData, JsonGenerator generator)
+      throws IOException {
+    generator.writeStartArray();
+    List<Types.NestedField> fields = partitionType.fields();
+    for (int pos = 0; pos < fields.size(); ++pos) {
+      Types.NestedField field = fields.get(pos);
+      Object partitionValue = partitionData.get(pos, Object.class);
+      SingleValueParser.toJson(field.type(), partitionValue, generator);
+    }
+    generator.writeEndArray();
+  }
+
+  private static PartitionData partitionFromJson(
+      Types.StructType partitionType, JsonNode partitionNode) {
+    Preconditions.checkArgument(
+        partitionNode.isArray(),
+        "Invalid partition data for content file: non-array (%s)",
+        partitionNode);

Review Comment:
   Yeah, I agree. I think that's a good call. I think the important part here is for file scan tasks that are sent over the wire, can respect the rest spec, and we could have fallback for Flink. In all new cases, we'll  be strict with what we send out.



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