This is an automated email from the ASF dual-hosted git repository. dianfu pushed a commit to branch release-2.2 in repository https://gitbox.apache.org/repos/asf/flink.git
commit 940d968c5fb2f353ecb6ebdac0a95e6ca0b52893 Author: Beetle brank <[email protected]> AuthorDate: Thu Sep 10 11:02:48 2026 +0800 [FLINK-23758][python] Fix semantics of Expression.__invert__ (#29148) --- flink-python/pyflink/table/expression.py | 2 +- flink-python/pyflink/table/tests/test_calc.py | 10 ++++++++++ flink-python/pyflink/table/tests/test_expression.py | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/flink-python/pyflink/table/expression.py b/flink-python/pyflink/table/expression.py index 64367287a7b..6409cf290ed 100644 --- a/flink-python/pyflink/table/expression.py +++ b/flink-python/pyflink/table/expression.py @@ -480,7 +480,7 @@ class Expression(Generic[T]): # logic functions __and__ = _binary_op("and") __or__ = _binary_op("or") - __invert__ = _unary_op('isNotTrue') + __invert__ = _unary_op("not") __rand__ = _binary_op("and") __ror__ = _binary_op("or") diff --git a/flink-python/pyflink/table/tests/test_calc.py b/flink-python/pyflink/table/tests/test_calc.py index 89d6c956270..677f628fcd3 100644 --- a/flink-python/pyflink/table/tests/test_calc.py +++ b/flink-python/pyflink/table/tests/test_calc.py @@ -37,6 +37,16 @@ class StreamTableCalcTests(PyFlinkStreamTableTestCase): self.assertEqual('[plus(a, 1), b, c]', query_operation.getProjectList().toString()) + def test_invert_nullable_boolean_expression(self): + schema = DataTypes.ROW([ + DataTypes.FIELD("a", DataTypes.BOOLEAN()) + ]) + table = self.t_env.from_elements([(True,), (False,), (None,)], schema) + + actual = [tuple(row) for row in table.select(table.a, ~table.a).execute().collect()] + + self.assertCountEqual(actual, [(True, False), (False, True), (None, None)]) + def test_alias(self): t = self.t_env.from_elements([(1, 'Hi', 'Hello')], ['a', 'b', 'c']) t = t.alias("d", "e", "f") diff --git a/flink-python/pyflink/table/tests/test_expression.py b/flink-python/pyflink/table/tests/test_expression.py index 33628437453..22a1fff4fbd 100644 --- a/flink-python/pyflink/table/tests/test_expression.py +++ b/flink-python/pyflink/table/tests/test_expression.py @@ -53,7 +53,7 @@ class PyFlinkBatchExpressionTests(PyFlinkTestCase): self.assertEqual('and(a, b)', str(expr1 & expr2)) self.assertEqual('or(a, b)', str(expr1 | expr2)) self.assertEqual('isNotTrue(a)', str(expr1.is_not_true)) - self.assertEqual('isNotTrue(a)', str(~expr1)) + self.assertEqual('not(a)', str(~expr1)) # arithmetic functions self.assertEqual('plus(a, b)', str(expr1 + expr2))
