From 58fad097209e37d727988d03a60367b6e7dbc917 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 23 Mar 2022 10:07:13 -0400 Subject: Add option to disable from linting for table valued function Added new parameter :paramref:`.FunctionElement.table_valued.joins_implicitly`, for the :meth:`.FunctionElement.table_valued` construct. This parameter indicates that the given table-valued function implicitly joins to the table it refers towards, essentially disabling the "from linting" feature, i.e. the "cartesian product" warning, from taking effect due to the presence of this parameter. May be used for functions such as ``func.json_each()``. Fixes: #7845 Change-Id: I80edcb74efbd4417172132c0db4d9c756fdd5eae (cherry picked from commit 04dcc5c704dbf0b22705523e263e512c24936175) --- test/sql/test_from_linter.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/sql') diff --git a/test/sql/test_from_linter.py b/test/sql/test_from_linter.py index a22913868..4a4d907f9 100644 --- a/test/sql/test_from_linter.py +++ b/test/sql/test_from_linter.py @@ -1,6 +1,10 @@ +from sqlalchemy import column +from sqlalchemy import func from sqlalchemy import Integer +from sqlalchemy import JSON from sqlalchemy import select from sqlalchemy import sql +from sqlalchemy import table from sqlalchemy import testing from sqlalchemy import true from sqlalchemy.testing import config @@ -161,6 +165,30 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): assert start is p3 assert froms == {p1} + @testing.combinations(True, False, argnames="joins_implicitly") + def test_table_valued(self, joins_implicitly): + """test #7845""" + my_table = table( + "tbl", + column("id", Integer), + column("data", JSON()), + ) + + sub_dict = my_table.c.data["d"] + tv = func.json_each(sub_dict).table_valued( + "key", joins_implicitly=joins_implicitly + ) + has_key = tv.c.key == "f" + stmt = select(my_table.c.id).where(has_key) + froms, start = find_unmatching_froms(stmt, my_table) + + if joins_implicitly: + is_(start, None) + is_(froms, None) + else: + assert start == my_table + assert froms == {tv} + def test_count_non_eq_comparison_operators(self): query = select(self.a).where(self.a.c.col_a > self.b.c.col_b) froms, start = find_unmatching_froms(query, self.a) -- cgit v1.2.1