Fokko commented on code in PR #1693:
URL: https://github.com/apache/iceberg-python/pull/1693#discussion_r1965135665
##########
pyiceberg/table/upsert_util.py:
##########
@@ -36,7 +37,17 @@ def create_match_filter(df: pyarrow_table, join_cols:
list[str]) -> BooleanExpre
if len(join_cols) == 1:
return In(join_cols[0], unique_keys[0].to_pylist())
else:
- return Or(*[And(*[EqualTo(col, row[col]) for col in join_cols]) for
row in unique_keys.to_pylist()])
+ filters: List[BooleanExpression] = [
+ cast(BooleanExpression, And(*[EqualTo(col, row[col]) for col in
join_cols])) for row in unique_keys.to_pylist()
+ ]
+
+ if not filters:
+ return In(join_cols[0], [])
+
+ if len(filters) == 1:
+ return filters[0]
+
+ return functools.reduce(lambda a, b: Or(a, b), filters)
Review Comment:
You are 💯 right, this was before my morning coffee:
```
➜ iceberg-python git:(main) ✗ python3
Python 3.10.14 (main, Mar 19 2024, 21:46:16) [Clang 15.0.0
(clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyiceberg.expressions import In
>>> In('vo', [])
AlwaysFalse()
```
##########
pyiceberg/table/upsert_util.py:
##########
@@ -36,7 +37,17 @@ def create_match_filter(df: pyarrow_table, join_cols:
list[str]) -> BooleanExpre
if len(join_cols) == 1:
return In(join_cols[0], unique_keys[0].to_pylist())
else:
- return Or(*[And(*[EqualTo(col, row[col]) for col in join_cols]) for
row in unique_keys.to_pylist()])
+ filters: List[BooleanExpression] = [
+ cast(BooleanExpression, And(*[EqualTo(col, row[col]) for col in
join_cols])) for row in unique_keys.to_pylist()
+ ]
+
+ if not filters:
+ return In(join_cols[0], [])
+
+ if len(filters) == 1:
+ return filters[0]
+
+ return functools.reduce(lambda a, b: Or(a, b), filters)
Review Comment:
What do you think of the following:
```suggestion
if len(filters) == 0:
return AlwaysFalse()
elif len(filters) == 1:
return filters[0]
else:
return functools.reduce(lambda a, b: Or(a, b), filters)
```
--
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]