Skip to content

Commit

Permalink
test_null_negation for multi_table setting
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervg committed Oct 9, 2024
1 parent d8b7d16 commit 9daf09f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion blendsql/parse/_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_multi_table_blendsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 9daf09f

Please sign in to comment.