summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-24 08:03:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-24 08:03:48 +0000
commit36db14f4c6c28209371d563d76697df0172e337f (patch)
tree527347be54a38fc9b14fe1fa04c27a4bbae44016 /tests/test_optimizer.py
parentReleasing debian version 17.4.1-1. (diff)
downloadsqlglot-36db14f4c6c28209371d563d76697df0172e337f.tar.xz
sqlglot-36db14f4c6c28209371d563d76697df0172e337f.zip
Merging upstream version 17.7.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_optimizer.py')
-rw-r--r--tests/test_optimizer.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
index 0608903..cd0b9b1 100644
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -427,6 +427,27 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
{"s.b"},
)
+ # Check that parentheses don't introduce a new scope unless an alias is attached
+ sql = "SELECT * FROM (((SELECT * FROM (t1 JOIN t2) AS t3) JOIN (SELECT * FROM t4)))"
+ expression = parse_one(sql)
+ for scopes in traverse_scope(expression), list(build_scope(expression).traverse()):
+ self.assertEqual(len(scopes), 4)
+
+ self.assertEqual(scopes[0].expression.sql(), "t1, t2")
+ self.assertEqual(set(scopes[0].sources), {"t1", "t2"})
+
+ self.assertEqual(scopes[1].expression.sql(), "SELECT * FROM (t1, t2) AS t3")
+ self.assertEqual(set(scopes[1].sources), {"t3"})
+
+ self.assertEqual(scopes[2].expression.sql(), "SELECT * FROM t4")
+ self.assertEqual(set(scopes[2].sources), {"t4"})
+
+ self.assertEqual(
+ scopes[3].expression.sql(),
+ "SELECT * FROM (((SELECT * FROM (t1, t2) AS t3), (SELECT * FROM t4)))",
+ )
+ self.assertEqual(set(scopes[3].sources), {""})
+
@patch("sqlglot.optimizer.scope.logger")
def test_scope_warning(self, logger):
self.assertEqual(len(traverse_scope(parse_one("WITH q AS (@y) SELECT * FROM q"))), 1)