You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: StructType fails to deserialize JSON with type field (apache#1822)
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 apache#1749.
## What changes are included in this PR?
Fixes a bug in the `StructType` deserializer that causes JSON
deserialization to fail with the error `expected ',' or '}' at line 1
column 8`.
**Root Cause:**
The `StructType::Deserialize` implementation was not properly consuming
the `"type"` field value when deserializing JSON like:
```json
{"type":"struct","fields":[{"id":1,"name":"foo","required":true,"type":"string"}]}
```
In serde's visitor pattern, when you call `map.next_key()`, you must
call `map.next_value()` to consume the corresponding value, even if
you're discarding it. The deserializer was calling `next_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:
- Modified `StructTypeVisitor::visit_map` to properly consume the type
field value
- Added validation that the type field equals "struct"
## Are these changes tested?
Yes, two new unit tests have been added to
`crates/iceberg/src/spec/datatypes.rs`:
1. **`struct_type_with_type_field`** - Verifies that `StructType`
successfully deserializes from JSON containing the `"type":"struct"`
field. This test would fail before the fix with the error `expected ','
or '}' at line 1 column 8`
2. **`struct_type_rejects_wrong_type`** - Validates that the
deserializer properly rejects JSON with incorrect type values (e.g.,
`"type":"list"`)
---------
Co-authored-by: Renjie Liu <[email protected]>
0 commit comments