@@ -1710,28 +1710,39 @@ def test_nonnull_annotation(self):
17101710 )
17111711 )
17121712
1713+ for predicate in (">" , "<" , ">=" , "<=" , "=" , "!=" , "<>" , "LIKE" , "NOT LIKE" ):
1714+ for operand , nonnull in (("1" , True ), ("foo.id" , False )):
1715+ sql_predicate = f"{ operand } { predicate } { operand } "
1716+ with self .subTest (f"Test NULL propagation for predicate: { predicate } " ):
1717+ sql = f"SELECT { sql_predicate } FROM foo"
1718+ query = parse_one (sql )
1719+ annotated = annotate_types (query , schema = schema )
1720+ assert annotated .selects [0 ].type == exp .DataType .build (
1721+ "BOOLEAN" , nonnull = nonnull
1722+ )
1723+
1724+ for predicate in ("IS NULL" , "IS NOT NULL" ):
1725+ sql_predicate = f"foo.id { predicate } "
1726+ with self .subTest (f"Test NULL propagation for predicate: { predicate } " ):
1727+ sql = f"SELECT { sql_predicate } FROM foo"
1728+ query = parse_one (sql )
1729+ annotated = annotate_types (query , schema = schema )
1730+ assert annotated .selects [0 ].type == exp .DataType .build ("BOOLEAN" , nonnull = True )
1731+
17131732 for connector in ("AND" , "OR" ):
17141733 for predicate in (">" , "<" , ">=" , "<=" , "=" , "!=" , "<>" , "LIKE" , "NOT LIKE" ):
17151734 for operand , nonnull in (("1" , True ), ("foo.id" , False )):
1716- sql_predicate = f"{ operand } { predicate } { operand } "
1735+ sql_predicate = f"({ operand } { predicate } { operand } )"
1736+ sql_connector = f"{ sql_predicate } { connector } { sql_predicate } "
17171737 with self .subTest (
1718- f"Test NULL propagation for connector: { connector } with predicate : { sql_predicate } "
1738+ f"Test NULL propagation for connector: { connector } with predicates : { predicate } "
17191739 ):
1720- sql = f"SELECT { sql_predicate } FROM foo"
1740+ sql = f"SELECT { sql_connector } FROM foo"
17211741 query = parse_one (sql )
17221742 annotated = annotate_types (query , schema = schema )
17231743 assert annotated .selects [0 ].type == exp .DataType .build (
17241744 "BOOLEAN" , nonnull = nonnull
17251745 )
1726- for predicate in ("IS NULL" , "IS NOT NULL" ):
1727- sql_predicate = f"foo.id { predicate } "
1728- with self .subTest (
1729- f"Test NULL propagation for connector: { connector } with predicate: { sql_predicate } "
1730- ):
1731- sql = f"SELECT { sql_predicate } FROM foo"
1732- query = parse_one (sql )
1733- annotated = annotate_types (query , schema = schema )
1734- assert annotated .selects [0 ].type == exp .DataType .build ("BOOLEAN" , nonnull = True )
17351746
17361747 for unary , unary_type in (("NOT" , "BOOLEAN" ), ("-" , "INT" )):
17371748 for value , nonnull in (("1" , True ), ("foo.id" , False )):
0 commit comments