Skip to content

Commit 0d9b648

Browse files
committed
more tests
1 parent f67e77f commit 0d9b648

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

tests/test_optimizer.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,28 +1718,39 @@ def test_nonnull_annotation(self):
17181718
)
17191719
)
17201720

1721+
for predicate in (">", "<", ">=", "<=", "=", "!=", "<>", "LIKE", "NOT LIKE"):
1722+
for operand, nonnull in (("1", True), ("foo.id", False)):
1723+
sql_predicate = f"{operand} {predicate} {operand}"
1724+
with self.subTest(f"Test NULL propagation for predicate: {predicate}"):
1725+
sql = f"SELECT {sql_predicate} FROM foo"
1726+
query = parse_one(sql)
1727+
annotated = annotate_types(query, schema=schema)
1728+
assert annotated.selects[0].type == exp.DataType.build(
1729+
"BOOLEAN", nonnull=nonnull
1730+
)
1731+
1732+
for predicate in ("IS NULL", "IS NOT NULL"):
1733+
sql_predicate = f"foo.id {predicate}"
1734+
with self.subTest(f"Test NULL propagation for predicate: {predicate}"):
1735+
sql = f"SELECT {sql_predicate} FROM foo"
1736+
query = parse_one(sql)
1737+
annotated = annotate_types(query, schema=schema)
1738+
assert annotated.selects[0].type == exp.DataType.build("BOOLEAN", nonnull=True)
1739+
17211740
for connector in ("AND", "OR"):
17221741
for predicate in (">", "<", ">=", "<=", "=", "!=", "<>", "LIKE", "NOT LIKE"):
17231742
for operand, nonnull in (("1", True), ("foo.id", False)):
1724-
sql_predicate = f"{operand} {predicate} {operand}"
1743+
sql_predicate = f"({operand} {predicate} {operand})"
1744+
sql_connector = f"{sql_predicate} {connector} {sql_predicate}"
17251745
with self.subTest(
1726-
f"Test NULL propagation for connector: {connector} with predicate: {sql_predicate}"
1746+
f"Test NULL propagation for connector: {connector} with predicates: {predicate}"
17271747
):
1728-
sql = f"SELECT {sql_predicate} FROM foo"
1748+
sql = f"SELECT {sql_connector} FROM foo"
17291749
query = parse_one(sql)
17301750
annotated = annotate_types(query, schema=schema)
17311751
assert annotated.selects[0].type == exp.DataType.build(
17321752
"BOOLEAN", nonnull=nonnull
17331753
)
1734-
for predicate in ("IS NULL", "IS NOT NULL"):
1735-
sql_predicate = f"foo.id {predicate}"
1736-
with self.subTest(
1737-
f"Test NULL propagation for connector: {connector} with predicate: {sql_predicate}"
1738-
):
1739-
sql = f"SELECT {sql_predicate} FROM foo"
1740-
query = parse_one(sql)
1741-
annotated = annotate_types(query, schema=schema)
1742-
assert annotated.selects[0].type == exp.DataType.build("BOOLEAN", nonnull=True)
17431754

17441755
for unary, unary_type in (("NOT", "BOOLEAN"), ("-", "INT")):
17451756
for value, nonnull in (("1", True), ("foo.id", False)):

0 commit comments

Comments
 (0)