summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-24 08:03:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-24 08:03:45 +0000
commitca57dc468e5d8d0920e964d45ad25271ae6e633d (patch)
tree319d8bffcb5c3e9afe9e62beca9ef401480578d2 /tests/test_optimizer.py
parentAdding upstream version 17.4.1. (diff)
downloadsqlglot-ca57dc468e5d8d0920e964d45ad25271ae6e633d.tar.xz
sqlglot-ca57dc468e5d8d0920e964d45ad25271ae6e633d.zip
Adding upstream version 17.7.0.upstream/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)