Skip to content

Commit 6388b4d

Browse files
authored
Upsert: Align codestyle (#1710)
Now we have the syntactic sugar (#1697), we don't need Lambda's anymore and can use the `operator.{and_,or_}` functions. Also, the reduce is okay with just having a single argument, while `And(*[EqualTo('a', 22)])` would fail. ``` 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. >>> import functools >>> functools.reduce(lambda a, b: a + b, [1]) 1 >>> functools.reduce(lambda a, b: a + b, [1, 2]) 3 ```
1 parent 06404a5 commit 6388b4d

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

pyiceberg/table/upsert_util.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@
1616
# under the License.
1717
import functools
1818
import operator
19-
from typing import List, cast
2019

2120
import pyarrow as pa
2221
from pyarrow import Table as pyarrow_table
2322
from pyarrow import compute as pc
2423

2524
from pyiceberg.expressions import (
2625
AlwaysFalse,
27-
And,
2826
BooleanExpression,
2927
EqualTo,
3028
In,
31-
Or,
3229
)
3330

3431

@@ -38,16 +35,11 @@ def create_match_filter(df: pyarrow_table, join_cols: list[str]) -> BooleanExpre
3835
if len(join_cols) == 1:
3936
return In(join_cols[0], unique_keys[0].to_pylist())
4037
else:
41-
filters: List[BooleanExpression] = [
42-
cast(BooleanExpression, And(*[EqualTo(col, row[col]) for col in join_cols])) for row in unique_keys.to_pylist()
38+
filters = [
39+
functools.reduce(operator.and_, [EqualTo(col, row[col]) for col in join_cols]) for row in unique_keys.to_pylist()
4340
]
4441

45-
if len(filters) == 0:
46-
return AlwaysFalse()
47-
elif len(filters) == 1:
48-
return filters[0]
49-
else:
50-
return functools.reduce(lambda a, b: Or(a, b), filters)
42+
return AlwaysFalse() if len(filters) == 0 else functools.reduce(operator.or_, filters)
5143

5244

5345
def has_duplicate_rows(df: pyarrow_table, join_cols: list[str]) -> bool:

0 commit comments

Comments
 (0)