Skip to content

Commit

Permalink
Adding a test case for named args in QAIngredient
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervg committed Feb 22, 2024
1 parent fc4aae7 commit 88ed9a6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_multi_table_blendsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,42 @@ def test_cte_qa_multi_exec(db, ingredients):
# assert smoothie.meta.num_values_passed == passed_to_ingredient.values[0].item()


def test_cte_qa_named_multi_exec(db, ingredients):
blendsql = """
{{
get_table_size(
question='Table size?',
context=(
WITH a AS (
SELECT * FROM (SELECT DISTINCT * FROM portfolio) as w
WHERE {{starts_with('F', 'w::Symbol')}} = TRUE
) SELECT * FROM a WHERE LENGTH(a.Symbol) > 2
)
)
}}
"""
sql = """
WITH a AS (
SELECT * FROM (SELECT DISTINCT * FROM portfolio) as w
WHERE w.Symbol LIKE 'F%'
) SELECT COUNT(*) FROM a WHERE LENGTH(a.Symbol) > 2
"""
smoothie = blend(
query=blendsql,
db=db,
ingredients=ingredients,
)
sql_df = db.execute_query(sql)
assert_equality(smoothie=smoothie, sql_df=sql_df, args=["F"])
# Make sure we only pass what's necessary to our ingredient
# passed_to_ingredient = db.execute_query(
# """
# SELECT COUNT(DISTINCT Symbol) FROM portfolio WHERE LENGTH(Symbol) > 3 AND Quantity > 200
# """
# )
# assert smoothie.meta.num_values_passed == passed_to_ingredient.values[0].item()


# def test_subquery_alias_with_join_multi_exec(db, ingredients):
# blendsql = """
# SELECT w."Percent of Account" FROM (SELECT * FROM "portfolio" WHERE Quantity > 200 OR "Today''s Gain/Loss Percent" > 0.05) as w
Expand Down

0 comments on commit 88ed9a6

Please sign in to comment.