rdblue commented on code in PR #4632:
URL: https://github.com/apache/iceberg/pull/4632#discussion_r860139741
##########
core/src/main/java/org/apache/iceberg/MetadataUpdateParser.java:
##########
@@ -140,21 +170,73 @@ public static MetadataUpdate fromJson(JsonNode jsonNode) {
throw new UnsupportedOperationException("Not implemented: AssignUUID");
case UPGRADE_FORMAT_VERSION:
return readAsUpgradeFormatVersion(jsonNode);
+ case ADD_SCHEMA:
+ return readAsAddSchema(jsonNode);
+ case SET_CURRENT_SCHEMA:
+ return readAsSetCurrentSchema(jsonNode);
+ case SET_DEFAULT_PARTITION_SPEC:
+ return readAsSetDefaultPartitionSpec(jsonNode);
+ case ADD_PARTITION_SPEC:
+ case ADD_SORT_ORDER:
+ case SET_DEFAULT_SORT_ORDER:
+ case ADD_SNAPSHOT:
+ case REMOVE_SNAPSHOTS:
+ case SET_SNAPSHOT_REF:
+ case SET_PROPERTIES:
+ case REMOVE_PROPERTIES:
+ case SET_LOCATION:
+ throw new UnsupportedOperationException("Not Implemented:
MetadataUpdatefromJson for " + action);
default:
throw new UnsupportedOperationException(
String.format("Cannot convert metadata update action to json: %s",
action));
}
}
- // Write all fields specific to UpgradeFormatVersion
- private static void
writeUpgradeFormatVersion(MetadataUpdate.UpgradeFormatVersion update,
JsonGenerator gen)
+ private static void
writeAsUpgradeFormatVersion(MetadataUpdate.UpgradeFormatVersion update,
JsonGenerator gen)
throws IOException {
gen.writeNumberField(FORMAT_VERSION, update.formatVersion());
}
+ private static void writeAsAddSchema(MetadataUpdate.AddSchema update,
JsonGenerator gen) throws IOException {
+ gen.writeFieldName(SCHEMA);
+ SchemaParser.toJson(update.schema(), gen);
+ gen.writeNumberField(LAST_COLUMN_ID, update.lastColumnId());
+ }
+
+ private static void writeAsSetCurrentSchema(MetadataUpdate.SetCurrentSchema
update, JsonGenerator gen)
+ throws IOException {
+ gen.writeNumberField(SCHEMA_ID, update.schemaId());
+ }
+
+ private static void
writeAsSetDefaultPartitionSpec(MetadataUpdate.SetDefaultPartitionSpec update,
JsonGenerator gen)
+ throws IOException {
+ gen.writeNumberField(SPEC_ID, update.specId());
+ }
+
private static MetadataUpdate readAsUpgradeFormatVersion(JsonNode node) {
int formatVersion = JsonUtil.getInt(FORMAT_VERSION, node);
return new MetadataUpdate.UpgradeFormatVersion(formatVersion);
}
+
+ private static MetadataUpdate readAsAddSchema(JsonNode node) {
+ Preconditions.checkArgument(node.hasNonNull(SCHEMA),
+ "Cannot parse missing field: schema");
+ JsonNode schemaNode = node.get(SCHEMA);
+ Preconditions.checkArgument(schemaNode.isObject(),
+ "Invalid type for schema field. Expected object");
Review Comment:
I think this is already checked in `SchemaParser.fromJson`. It reads the
type and then makes sure it is a struct, which should provide a good error
message.
--
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]