From 9daf09f3341bbcf44709b45eaea12a051871e2be Mon Sep 17 00:00:00 2001 From: parkervg Date: Wed, 9 Oct 2024 13:46:26 -0400 Subject: [PATCH] test_null_negation for multi_table setting --- blendsql/parse/_transforms.py | 2 +- tests/test_multi_table_blendsql.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/blendsql/parse/_transforms.py b/blendsql/parse/_transforms.py index 52cb483c..8b3a1348 100644 --- a/blendsql/parse/_transforms.py +++ b/blendsql/parse/_transforms.py @@ -43,7 +43,7 @@ def extract_multi_table_predicates( if isinstance(node, exp.Table): if node.name != tablename: return None - if isinstance(node, exp.Predicate): + if isinstance(node, (exp.Predicate, exp.Unary)): # Search for child table, in current view # This below ensures we don't go into subqueries child_table = find_in_scope(node, exp.Table) diff --git a/tests/test_multi_table_blendsql.py b/tests/test_multi_table_blendsql.py index 3d12dd02..343d0598 100644 --- a/tests/test_multi_table_blendsql.py +++ b/tests/test_multi_table_blendsql.py @@ -664,3 +664,28 @@ def test_join_with_multiple_ingredients(db, ingredients): ) sql_df = db.execute_to_df(sql) assert_equality(smoothie=smoothie, sql_df=sql_df) + + +@pytest.mark.parametrize("db", databases) +def test_null_negation(db, ingredients): + blendsql = """ + SELECT DISTINCT Name FROM constituents + LEFT JOIN account_history ON constituents.Symbol = account_history.Symbol + WHERE account_history."Settlement Date" IS NOT NULL + AND {{starts_with('F', 'account_history::Account')}} + ORDER BY constituents.Name + """ + sql = """ + SELECT DISTINCT Name FROM constituents + LEFT JOIN account_history ON constituents.Symbol = account_history.Symbol + WHERE account_history."Settlement Date" IS NOT NULL + AND account_history.Account LIKE 'F%' + ORDER BY constituents.Name + """ + smoothie = blend( + query=blendsql, + db=db, + ingredients=ingredients, + ) + sql_df = db.execute_to_df(sql) + assert_equality(smoothie=smoothie, sql_df=sql_df)