Skip to content

Commit 5dcbcb2

Browse files
authored
feat: replace ExpressionA with IsNull("a") (#2651)
Closes #2637 # Rationale for this change ## Are these changes tested? Yes, tests and lint passing ## Are there any user-facing changes?
1 parent 36897b7 commit 5dcbcb2

File tree

1 file changed

+29
-52
lines changed

1 file changed

+29
-52
lines changed

tests/expressions/test_expressions.py

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,6 @@
7777
StringType,
7878
StructType,
7979
)
80-
from pyiceberg.utils.singleton import Singleton
81-
82-
83-
class ExpressionA(BooleanExpression, Singleton):
84-
def __invert__(self) -> BooleanExpression:
85-
return ExpressionB()
86-
87-
def __repr__(self) -> str:
88-
return "ExpressionA()"
89-
90-
def __str__(self) -> str:
91-
return "testexpra"
92-
93-
94-
class ExpressionB(BooleanExpression, Singleton):
95-
def __invert__(self) -> BooleanExpression:
96-
return ExpressionA()
97-
98-
def __repr__(self) -> str:
99-
return "ExpressionB()"
100-
101-
def __str__(self) -> str:
102-
return "testexprb"
10380

10481

10582
def test_isnull_inverse() -> None:
@@ -504,18 +481,18 @@ def test_bind_case_insensitive(pred: UnboundPredicate[Any], table_schema_simple:
504481
"exp, testexpra, testexprb",
505482
[
506483
(
507-
And(ExpressionA(), ExpressionB()),
508-
And(ExpressionA(), ExpressionB()),
509-
Or(ExpressionA(), ExpressionB()),
484+
And(IsNull("a"), IsNull("b")),
485+
And(IsNull("a"), IsNull("b")),
486+
Or(IsNull("a"), IsNull("b")),
510487
),
511488
(
512-
Or(ExpressionA(), ExpressionB()),
513-
Or(ExpressionA(), ExpressionB()),
514-
And(ExpressionA(), ExpressionB()),
489+
Or(IsNull("a"), IsNull("b")),
490+
Or(IsNull("a"), IsNull("b")),
491+
And(IsNull("a"), IsNull("b")),
515492
),
516-
(Not(ExpressionA()), Not(ExpressionA()), ExpressionB()),
517-
(ExpressionA(), ExpressionA(), ExpressionB()),
518-
(ExpressionB(), ExpressionB(), ExpressionA()),
493+
(Not(IsNull("a")), Not(IsNull("a")), IsNull("b")),
494+
(IsNull("a"), IsNull("a"), IsNull("b")),
495+
(IsNull("b"), IsNull("b"), IsNull("a")),
519496
(
520497
In(Reference("foo"), ("hello", "world")),
521498
In(Reference("foo"), ("hello", "world")),
@@ -536,16 +513,16 @@ def test_eq(exp: BooleanExpression, testexpra: BooleanExpression, testexprb: Boo
536513
"lhs, rhs",
537514
[
538515
(
539-
And(ExpressionA(), ExpressionB()),
540-
Or(ExpressionB(), ExpressionA()),
516+
And(IsNull("a"), IsNull("b")),
517+
Or(NotNull("a"), NotNull("b")),
541518
),
542519
(
543-
Or(ExpressionA(), ExpressionB()),
544-
And(ExpressionB(), ExpressionA()),
520+
Or(IsNull("a"), IsNull("b")),
521+
And(NotNull("a"), NotNull("b")),
545522
),
546523
(
547-
Not(ExpressionA()),
548-
ExpressionA(),
524+
Not(IsNull("a")),
525+
IsNull("a"),
549526
),
550527
(
551528
In(Reference("foo"), ("hello", "world")),
@@ -559,8 +536,8 @@ def test_eq(exp: BooleanExpression, testexpra: BooleanExpression, testexprb: Boo
559536
(LessThan(Reference("foo"), 5), GreaterThanOrEqual(Reference("foo"), 5)),
560537
(EqualTo(Reference("foo"), 5), NotEqualTo(Reference("foo"), 5)),
561538
(
562-
ExpressionA(),
563-
ExpressionB(),
539+
IsNull("a"),
540+
NotNull("a"),
564541
),
565542
],
566543
)
@@ -572,14 +549,14 @@ def test_negate(lhs: BooleanExpression, rhs: BooleanExpression) -> None:
572549
"lhs, rhs",
573550
[
574551
(
575-
And(ExpressionA(), ExpressionB(), ExpressionA()),
576-
And(ExpressionA(), And(ExpressionB(), ExpressionA())),
552+
And(IsNull("a"), IsNull("b"), IsNull("a")),
553+
And(IsNull("a"), And(IsNull("b"), IsNull("a"))),
577554
),
578555
(
579-
Or(ExpressionA(), ExpressionB(), ExpressionA()),
580-
Or(ExpressionA(), Or(ExpressionB(), ExpressionA())),
556+
Or(IsNull("a"), IsNull("b"), IsNull("a")),
557+
Or(IsNull("a"), Or(IsNull("b"), IsNull("a"))),
581558
),
582-
(Not(Not(ExpressionA())), ExpressionA()),
559+
(Not(Not(IsNull("a"))), IsNull("a")),
583560
],
584561
)
585562
def test_reduce(lhs: BooleanExpression, rhs: BooleanExpression) -> None:
@@ -589,13 +566,13 @@ def test_reduce(lhs: BooleanExpression, rhs: BooleanExpression) -> None:
589566
@pytest.mark.parametrize(
590567
"lhs, rhs",
591568
[
592-
(And(AlwaysTrue(), ExpressionB()), ExpressionB()),
593-
(And(AlwaysFalse(), ExpressionB()), AlwaysFalse()),
594-
(And(ExpressionB(), AlwaysTrue()), ExpressionB()),
595-
(Or(AlwaysTrue(), ExpressionB()), AlwaysTrue()),
596-
(Or(AlwaysFalse(), ExpressionB()), ExpressionB()),
597-
(Or(ExpressionA(), AlwaysFalse()), ExpressionA()),
598-
(Not(Not(ExpressionA())), ExpressionA()),
569+
(And(AlwaysTrue(), IsNull("b")), IsNull("b")),
570+
(And(AlwaysFalse(), IsNull("b")), AlwaysFalse()),
571+
(And(IsNull("b"), AlwaysTrue()), IsNull("b")),
572+
(Or(AlwaysTrue(), IsNull("b")), AlwaysTrue()),
573+
(Or(AlwaysFalse(), IsNull("b")), IsNull("b")),
574+
(Or(IsNull("a"), AlwaysFalse()), IsNull("a")),
575+
(Not(Not(IsNull("a"))), IsNull("a")),
599576
(Not(AlwaysTrue()), AlwaysFalse()),
600577
(Not(AlwaysFalse()), AlwaysTrue()),
601578
],

0 commit comments

Comments
 (0)