apache / apache/iceberg-python

Add explicit truthiness semantics for constant BooleanExpressions

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

説明

While this PR can use expression negation via `__invert__,` I think it may be worth supporting Python truthiness for the constant expressions in a follow-up:
```
class AlwaysTrue:
def __bool__(self) -> bool:
return True

class AlwaysFalse:
def __bool__(self) -> bool:
return False
```

That would make patterns like this behave intuitively:
```
if not self.visit_starts_with(term, literal):
return AlwaysTrue()
```

When adding this, we should also be careful that Python truthiness is for control flow, not expression construction: `not expr` returns a Python `bool`, while `~expr` returns a negated BooleanExpression. It would probably be safest for non-constant `BooleanExpression.__bool__` to raise, with only `AlwaysTrue` and `AlwaysFalse` overriding it. The follow-up should also audit optional-expression checks like `expr or AlwaysTrue()` and REST residual/filter handling so explicit `AlwaysFalse()` values are not treated as missing.

_Originally posted by @kevinjqliu in https://github.com/apache/iceberg-python/issues/3503#issuecomment-4763176953_

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

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

調査の方向性

まず BooleanExpression、AlwaysTrue、AlwaysFalse を見つけ、次に issue で言及されている optional-expression のチェックと REST の residual/filter 処理を調べます。定数式だけが Python の truthiness をサポートし、非定数式はそれを拒否し、明示的な AlwaysFalse() 値が欠落値として扱われずに保持されることを確認してください。

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

評価

技術スタック
python
領域
databases
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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