fix: StructType fails to deserialize JSON with type field #1822
+54
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fix enables proper interoperability with Iceberg implementations that include the type discriminator field in their JSON serialization (such as Apache Iceberg Java).
Which issue does this PR close?
Partially address #1749.
What changes are included in this PR?
Fixes a bug in the
StructTypedeserializer that causes JSON deserialization to fail with the errorexpected ',' or '}' at line 1 column 8.Root Cause:
The
StructType::Deserializeimplementation was not properly consuming the"type"field value when deserializing JSON like:{"type":"struct","fields":[{"id":1,"name":"foo","required":true,"type":"string"}]}In serde's visitor pattern, when you call
map.next_key(), you must callmap.next_value()to consume the corresponding value, even if you're discarding it. The deserializer was callingnext_key()for the "type" field but not consuming its value, causing the parser to remain stuck at the value position and fail when encountering the next field.Changes:
StructTypeVisitor::visit_mapto properly consume the type field valueAre these changes tested?
Yes, two new unit tests have been added to
crates/iceberg/src/spec/datatypes.rs:struct_type_with_type_field- Verifies thatStructTypesuccessfully deserializes from JSON containing the"type":"struct"field. This test would fail before the fix with the errorexpected ',' or '}' at line 1 column 8struct_type_rejects_wrong_type- Validates that the deserializer properly rejects JSON with incorrect type values (e.g.,"type":"list")