apache / apache/iceberg-python

Upsert with None values fails on "Invalid literal value: None"

Abierto
#2,426 7 comentarios 1 reacción 0 asignados Ver en GitHub
stale
Lenguaje dominante
Python
Estrellas
1.1k
Forks
581
Merge medio
1 d 17 h
PR fusionados (30 d)
77

Descripción

### Apache Iceberg version

main (development)

### Please describe the bug 🐞

Upserting a table fails when the input dataframe contains `None` in a join column.

I've reproduced this error by editing `test_upsert_with_nulls` from #1861, adding this at the end:

```python
# upsert table with null value
data_with_null = pa.Table.from_pylist(
[
{"foo": None, "bar": 1, "baz": False},
],
schema=schema,
)
upd = table.upsert(data_with_null, join_cols=["foo"])
```

The `foo` column contains `None`, causing `TypeError: Invalid literal value: None`.

```
tests/table/test_upsert.py:720: in test_upsert_with_nulls
upd = table.upsert(data_with_null, join_cols=["foo"])
pyiceberg/table/__init__.py:1343: in upsert
return tx.upsert(
pyiceberg/table/__init__.py:798: in upsert
matched_predicate = upsert_util.create_match_filter(df, join_cols)
pyiceberg/table/upsert_util.py:37: in create_match_filter
return In(join_cols[0], unique_keys[0].to_pylist())
pyiceberg/expressions/__init__.py:682: in __new__
literals_set: Set[Literal[L]] = _to_literal_set(literals)
pyiceberg/expressions/__init__.py:52: in _to_literal_set
return {_to_literal(v) for v in values}
pyiceberg/expressions/__init__.py:52: in
return {_to_literal(v) for v in values}
pyiceberg/expressions/__init__.py:59: in _to_literal
return literal(value)
pyiceberg/expressions/literals.py:159: in literal
raise TypeError(f"Invalid literal value: {repr(value)}")
E TypeError: Invalid literal value: None
```

### Willingness to contribute

- [ ] I can contribute a fix for this bug independently
- [x] 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 con tests/table/test_upsert.py, especialmente test_upsert_with_nulls y la reproducción añadida; después, lee pyiceberg/table/upsert_util.py:create_match_filter y el manejo de literales de expresiones mostrado en el traceback. Confirma con la comunidad el comportamiento esperado para un valor null en la columna de join y, después, haz que funcione el caso de upsert y añade o actualiza una prueba de regresión que pase.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
databases
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
68/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.