Fix: Nested struct parsing fails to preserve nested fields (Issue #627)#628
Merged
laughingman7743 merged 1 commit intomasterfrom Nov 17, 2025
Merged
Conversation
This commit fixes a critical bug where nested STRUCT (ROW) types were
not being parsed correctly, causing nested fields to be lost during
data conversion.
## Problem
The `_parse_named_struct` function in `pyathena/converter.py` was using
simple comma-splitting which failed for nested structures like:
`{header={stamp=2024-01-01, seq=123}, x=4.736}`
This caused:
1. Incorrect splitting at commas inside nested braces
2. Nested fields being skipped due to brace-containing value filtering
## Solution
- Updated `_parse_named_struct` to use `_split_array_items` for
proper brace-depth-aware splitting
- Added recursive parsing for nested struct values
- Updated docstring to document nested struct support
## Testing
Added comprehensive test cases:
- Converter tests: 7 nested struct patterns + 3 array patterns
- SQLAlchemy integration tests: Query execution with nested ROW types
All existing tests pass without regression.
Fixes #627
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes nested STRUCT (ROW) type parsing where nested fields were being lost during data conversion.
Problem
Issue #627 reported that when querying tables with nested structs like:
The actual data
{header={stamp=xyz, seq=123}, x=4.736, y=0.583}was being incorrectly parsed as{'x': 4.736, 'y': 0.583}, with the entireheaderfield lost.Root Cause
The
_parse_named_structfunction inpyathena/converter.pyhad two issues:Simple comma splitting - Used
inner.split(",")which incorrectly split nested structures:Brace filtering - Skipped any key-value pairs containing
{}characters, removing all nested fieldsSolution
_parse_named_structto use_split_array_itemshelper for proper brace-depth-aware splitting{...}), call_to_structrecursivelyChanges
_parse_named_structfunctionTesting
All tests pass:
Test Coverage
Converter tests (
test_converter.py):{header={stamp=..., seq=...}, x=..., y=...}{outer={middle={inner=value}}}{level1={level2={level3=...}}}{pos={x, y}, vel={x, y}, timestamp=...}[{header={...}, x=...}]SQLAlchemy integration tests (
test_base.py):Verification
Fixes #627
🤖 Generated with Claude Code