From d4022e5868477a569d9be9ba8f7543344c00267b Mon Sep 17 00:00:00 2001 From: parkervg Date: Sat, 22 Jun 2024 19:42:55 -0400 Subject: [PATCH] test_apply_limit_with_predicate for 335c67a --- tests/test_single_table_blendsql.py | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_single_table_blendsql.py b/tests/test_single_table_blendsql.py index 52fe7219..8a3cf31a 100644 --- a/tests/test_single_table_blendsql.py +++ b/tests/test_single_table_blendsql.py @@ -565,5 +565,35 @@ def test_apply_limit(db, ingredients): assert smoothie.meta.num_values_passed == 1 +@pytest.mark.parametrize("db", databases) +def test_apply_limit_with_predicate(db, ingredients): + # commit 335c67a + blendsql = """ + SELECT {{get_length('length', 'transactions::merchant')}} + FROM transactions + WHERE amount > 1300 + ORDER BY merchant LIMIT 3 + """ + sql = """ + SELECT LENGTH(merchant) + FROM transactions + WHERE amount > 1300 + ORDER BY merchant LIMIT 3 + """ + smoothie = blend( + query=blendsql, + db=db, + ingredients=ingredients, + ) + sql_df = db.execute_to_df(sql) + assert_equality(smoothie=smoothie, sql_df=sql_df) + # Make sure we only pass what's necessary to our ingredient + passed_to_ingredient = db.execute_to_list( + """ + SELECT COUNT(DISTINCT merchant) FROM transactions WHERE amount > 1300 LIMIT 3 """ + )[0] + assert smoothie.meta.num_values_passed == passed_to_ingredient + + if __name__ == "__main__": pytest.main()