apache / apache/iceberg-python
TruncateTransform.satisfies_order_of raises AttributeError for different widths
- Lenguaje dominante
- Python
- Estrellas
- 1.1k
- Forks
- 581
- Merge medio
- 1 d 17 h
- PR fusionados (30 d)
- 78
Descripción
### Apache Iceberg version
0.11.0 (latest release)
### Please describe the bug 🐞
### Description
Calling `TruncateTransform.satisfies_order_of` with two valid truncate transforms that have different widths raises an `AttributeError` instead of returning a boolean.
Same-width comparisons work because the method returns early when the transforms are equal.
### Reproduction
```python
from pyiceberg.transforms import TruncateTransform
TruncateTransform(5).satisfies_order_of(TruncateTransform(3))
```
On `main` at commit `48e710d20ceeeaa637d5aeae7746b787410859f8`, this raises:
```text
AttributeError: 'TruncateTransform' object has no attribute '_source_type'
```
The failure reproduces consistently. The same code is also present in the 0.11.1 release.
### Expected behavior
The method should compare the truncate widths and return a boolean:
```python
assert TruncateTransform(5).satisfies_order_of(TruncateTransform(3))
assert not TruncateTransform(3).satisfies_order_of(TruncateTransform(5))
```
This matches the current Apache Iceberg Java implementation:
https://github.com/apache/iceberg/blob/25654ab4b29c8b5b5c20fc427da01cb70d94ed14/api/src/main/java/org/apache/iceberg/transforms/Truncate.java#L130-L141
### Cause
`TruncateTransform.__init__` initializes `_width` but not `_source_type`. However, `satisfies_order_of` still accesses the `source_type` property backed by `_source_type`:
https://github.com/apache/iceberg-python/blob/48e710d20ceeeaa637d5aeae7746b787410859f8/pyiceberg/transforms.py#L783-L905
The existing unit test only compares a transform with itself, so it returns before reaching the failing branch:
https://github.com/apache/iceberg-python/blob/48e710d20ceeeaa637d5aeae7746b787410859f8/tests/test_transforms.py#L501-L512
A focused fix could compare `TruncateTransform` widths directly, consistent with the Java implementation, and add regression cases for different widths.
I would be happy to contribute the fix and regression tests.
### 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
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza en pyiceberg/transforms.py, en TruncateTransform.satisfies_order_of, y revisa el constructor relacionado y la propiedad source_type. Ejecuta los casos específicos de tests/test_transforms.py alrededor de las líneas 501-512 y, después, añade cobertura para diferentes anchos. Se considera completado cuando las comparaciones devuelven los valores booleanos esperados sin acceder a un atributo no inicializado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- data-engineering
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 82/100