apache / apache/iceberg-python

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

オープン
#2,426 コメント 7 件 リアクション 1 件 担当者 0 名 GitHub で見る
stale
主要言語
Python
スター
1.1k
フォーク
581
平均マージ
1日 17時間
マージ済み PR(30日)
78

説明

### 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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

tests/table/test_upsert.py、特に test_upsert_with_nulls と追加された再現ケースから始め、次に pyiceberg/table/upsert_util.py:create_match_filter と、traceback に示されている式リテラルの処理を読んでください。Join 値が null の場合に期待される動作をコミュニティに確認し、そのうえで upsert のケースが動作するようにし、パスする回帰テストを追加または更新してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
68/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。