med9110 opened a new issue, #4098:
URL: https://github.com/apache/iceberg-python/issues/4098
### Apache Iceberg version
None
### Please describe the bug 🐞
### Apache Iceberg version
main (development)
### Please describe the bug
`JsonOutput.describe_refs()` emits one JSON object for each retention
property rather than one object per snapshot reference.
As a result, `pyiceberg --output=json list-refs <table>` can return three
objects for a table containing only one snapshot reference.
### Reproduction
```python
from pyiceberg.cli.output import JsonOutput
from pyiceberg.table.refs import SnapshotRefType
JsonOutput().describe_refs([
(
"main",
SnapshotRefType.BRANCH,
{
"min_snapshots_to_keep": "1",
"max_snapshot_age_ms": "432000000",
"max_ref_age_ms": "forever",
},
)
])
```
### Actual output
```json
[
{"name": "main", "type": "branch", "min_snapshots_to_keep": "1"},
{"name": "main", "type": "branch", "max_snapshot_age_ms": "432000000"},
{"name": "main", "type": "branch", "max_ref_age_ms": "forever"}
]
```
### Expected output
```json
[
{
"name": "main",
"type": "branch",
"min_snapshots_to_keep": "1",
"max_snapshot_age_ms": "432000000",
"max_ref_age_ms": "forever"
}
]
```
### Root cause
In `pyiceberg/cli/output.py`, `JsonOutput.describe_refs()` uses a nested
list comprehension:
```python
[
{"name": name, "type": type, detail_key: detail_val}
for name, type, detail in refs
for detail_key, detail_val in detail.items()
]
```
The inner loop creates a separate object for every entry in `detail`.
This is inconsistent with `ConsoleOutput.describe_refs()`, which renders one
row per reference.
### Suggested fix
Construct one dictionary per reference and merge the retention properties
into it. Add a regression test ensuring that one input reference produces one
complete JSON object, ideally also covering multiple references.
I reproduced the incorrect output by executing the current
list-comprehension logic in isolation. I have not yet run the full CLI against
a catalog.
### Willingness to contribute
I'd be happy to submit a focused fix with regression tests if the proposed
JSON structure is correct.
### Willingness to contribute
- [x] I can contribute a fix for this bug independently
- [ ] I would be willing to contribute a fix for this bug with guidance from
the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time
--
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]