amogh-jahagirdar commented on code in PR #13004:
URL: https://github.com/apache/iceberg/pull/13004#discussion_r2277648001
##########
core/src/main/java/org/apache/iceberg/ContentFileParser.java:
##########
@@ -135,28 +135,34 @@ static void toJson(ContentFile<?> contentFile,
PartitionSpec spec, JsonGenerator
}
static ContentFile<?> fromJson(JsonNode jsonNode, PartitionSpec spec) {
+ return fromJson(jsonNode, spec == null ? null : Map.of(spec.specId(),
spec));
+ }
+
+ static ContentFile<?> fromJson(JsonNode jsonNode, Map<Integer,
PartitionSpec> specsById) {
Preconditions.checkArgument(jsonNode != null, "Invalid JSON node for
content file: null");
Preconditions.checkArgument(
jsonNode.isObject(), "Invalid JSON node for content file: non-object
(%s)", jsonNode);
- Preconditions.checkArgument(spec != null, "Invalid partition spec: null");
-
+ Preconditions.checkArgument(specsById != null, "Invalid partition spec:
null");
int specId = JsonUtil.getInt(SPEC_ID, jsonNode);
FileContent fileContent = FileContent.valueOf(JsonUtil.getString(CONTENT,
jsonNode));
String filePath = JsonUtil.getString(FILE_PATH, jsonNode);
FileFormat fileFormat =
FileFormat.fromString(JsonUtil.getString(FILE_FORMAT, jsonNode));
PartitionData partitionData = null;
if (jsonNode.has(PARTITION)) {
- partitionData = new PartitionData(spec.partitionType());
+ partitionData = new PartitionData(specsById.get(specId).partitionType());
Review Comment:
Just noticed this but in the new structure we should probably have a clearer
message rather than a potential NPE in case the file somehow references a spec
ID that doesn't exist for some reason. It's unlikely but I think it's generally
better to have clearer error messages so that if it does happen a user knows
what to check rather than having to go deeper in the implementation. We can
also probably extract `specsById.get(specId)` into a separate variable since I
see it's called twice.
--
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]