rdblue commented on a change in pull request #2096:
URL: https://github.com/apache/iceberg/pull/2096#discussion_r575717535



##########
File path: core/src/main/java/org/apache/iceberg/TableMetadataParser.java
##########
@@ -262,7 +277,41 @@ static TableMetadata fromJson(FileIO io, InputFile file, 
JsonNode node) {
       lastSequenceNumber = TableMetadata.INITIAL_SEQUENCE_NUMBER;
     }
     int lastAssignedColumnId = JsonUtil.getInt(LAST_COLUMN_ID, node);
-    Schema schema = SchemaParser.fromJson(node.get(SCHEMA));
+
+    List<Schema> schemas;
+    int currentSchemaId;
+    Schema schema = null;
+
+    JsonNode schemaArray = node.get(SCHEMAS);
+    if (schemaArray != null) {
+      Preconditions.checkArgument(schemaArray.isArray(),
+          "Cannot parse schemas from non-array: %s", schemaArray);
+      // current schema ID is required when the schema array is present
+      currentSchemaId = JsonUtil.getInt(CURRENT_SCHEMA_ID, node);
+
+      // parse the schema array
+      ImmutableList.Builder<Schema> builder = ImmutableList.builder();
+      for (JsonNode schemaNode : schemaArray) {
+        Schema current = SchemaParser.fromJsonWithId(schemaNode);
+        if (current.schemaId() == currentSchemaId) {
+          schema = current;
+        }
+        builder.add(current);
+      }
+
+      Preconditions.checkArgument(schema != null,
+          "Cannot find schema with %s=%s from %s", CURRENT_SCHEMA_ID, 
currentSchemaId, SCHEMAS);
+
+      schemas = builder.build();
+
+    } else {
+      Preconditions.checkArgument(formatVersion == 1,
+          "%s must exist in format v%s", SCHEMAS, formatVersion);
+
+      currentSchemaId = TableMetadata.INITIAL_SCHEMA_ID;

Review comment:
       I think this should be `schema.schemaId()` instead of referencing the 
constant.




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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to