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