@@ -1700,46 +1700,36 @@ def test_annotate_object_construct(self):
17001700 annotated .selects [0 ].type .sql ("snowflake" ), 'OBJECT("foo" VARCHAR, "a b" VARCHAR)'
17011701 )
17021702
1703- def test_nonnull_annotation (self ):
1704- for literal_sql , literal_type in (( "1" , "INT" ), ( " 'foo'" , "VARCHAR" ), ( " 2.5", "DOUBLE" ) ):
1703+ def test_nullable_annotation (self ):
1704+ for literal_sql in ("1" , "'foo'" , "2.5" ):
17051705 with self .subTest (f"Test NULL annotation for literal: { literal_sql } " ):
17061706 sql = f"SELECT { literal_sql } "
17071707 query = parse_one (sql )
17081708 annotated = annotate_types (query )
1709- assert annotated .selects [0 ].type == exp . DataType . build ( literal_type , nonnull = True )
1709+ assert annotated .selects [0 ].meta . get ( "nullable" ) is False
17101710
17111711 schema = {"foo" : {"id" : "INT" }}
1712- sql = "SELECT foo.id FROM foo"
1713- query = parse_one (sql )
1714- annotated = annotate_types (query , schema = schema )
1715- self .assertTrue (
1716- annotated .selects [0 ].type .is_type (
1717- exp .DataType .build ("INT" , nonnull = False ), check_nullable = True
1718- )
1719- )
17201712
17211713 for predicate in (">" , "<" , ">=" , "<=" , "=" , "!=" , "<>" , "LIKE" , "NOT LIKE" ):
1722- for operand , nonnull in (("1" , True ), ("foo.id" , False )):
1714+ for operand , nullable in (("1" , False ), ("foo.id" , None )):
17231715 sql_predicate = f"{ operand } { predicate } { operand } "
17241716 with self .subTest (f"Test NULL propagation for predicate: { predicate } " ):
17251717 sql = f"SELECT { sql_predicate } FROM foo"
17261718 query = parse_one (sql )
17271719 annotated = annotate_types (query , schema = schema )
1728- assert annotated .selects [0 ].type == exp .DataType .build (
1729- "BOOLEAN" , nonnull = nonnull
1730- )
1720+ assert annotated .selects [0 ].meta .get ("nullable" ) is nullable
17311721
17321722 for predicate in ("IS NULL" , "IS NOT NULL" ):
17331723 sql_predicate = f"foo.id { predicate } "
17341724 with self .subTest (f"Test NULL propagation for predicate: { predicate } " ):
17351725 sql = f"SELECT { sql_predicate } FROM foo"
17361726 query = parse_one (sql )
17371727 annotated = annotate_types (query , schema = schema )
1738- assert annotated .selects [0 ].type == exp . DataType . build ( "BOOLEAN" , nonnull = True )
1728+ assert annotated .selects [0 ].meta . get ( "nullable" ) is False
17391729
17401730 for connector in ("AND" , "OR" ):
17411731 for predicate in (">" , "<" , ">=" , "<=" , "=" , "!=" , "<>" , "LIKE" , "NOT LIKE" ):
1742- for operand , nonnull in (("1" , True ), ("foo.id" , False )):
1732+ for operand , nullable in (("1" , False ), ("foo.id" , None )):
17431733 sql_predicate = f"({ operand } { predicate } { operand } )"
17441734 sql_connector = f"{ sql_predicate } { connector } { sql_predicate } "
17451735 with self .subTest (
@@ -1748,16 +1738,12 @@ def test_nonnull_annotation(self):
17481738 sql = f"SELECT { sql_connector } FROM foo"
17491739 query = parse_one (sql )
17501740 annotated = annotate_types (query , schema = schema )
1751- assert annotated .selects [0 ].type == exp .DataType .build (
1752- "BOOLEAN" , nonnull = nonnull
1753- )
1741+ assert annotated .selects [0 ].meta .get ("nullable" ) is nullable
17541742
1755- for unary , unary_type in (( "NOT" , "BOOLEAN" ), ( "-" , "INT" ) ):
1756- for value , nonnull in (("1" , True ), ("foo.id" , False )):
1743+ for unary in ("NOT" , "-" ):
1744+ for value , nullable in (("1" , False ), ("foo.id" , None )):
17571745 with self .subTest (f"Test NULL propagation for unary: { unary } with value: { value } " ):
17581746 sql = f"SELECT { unary } { value } FROM foo"
17591747 query = parse_one (sql )
17601748 annotated = annotate_types (query , schema = schema )
1761- assert annotated .selects [0 ].type == exp .DataType .build (
1762- unary_type , nonnull = nonnull
1763- )
1749+ assert annotated .selects [0 ].meta .get ("nullable" ) is nullable
0 commit comments