summaryrefslogtreecommitdiffstats
path: root/tests/test_parser.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-10 05:36:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-10 05:36:25 +0000
commit3517257d82008871c863f71a402742556dacc5cf (patch)
tree65704dee85c7aa830d01426c9bc3080a80c4e863 /tests/test_parser.py
parentAdding upstream version 17.2.0. (diff)
downloadsqlglot-3517257d82008871c863f71a402742556dacc5cf.tar.xz
sqlglot-3517257d82008871c863f71a402742556dacc5cf.zip
Adding upstream version 17.3.0.upstream/17.3.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_parser.py')
-rw-r--r--tests/test_parser.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 2fa6a09..891dcef 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -580,3 +580,58 @@ class TestParser(unittest.TestCase):
def test_parse_floats(self):
self.assertTrue(parse_one("1. ").is_number)
+
+ def test_parse_wrapped_tables(self):
+ expr = parse_one("select * from (table)")
+ self.assertIsInstance(expr.args["from"].this, exp.Table)
+ self.assertTrue(expr.args["from"].this.args["wrapped"])
+
+ expr = parse_one("select * from (((table)))")
+ self.assertIsInstance(expr.args["from"].this, exp.Table)
+ self.assertTrue(expr.args["from"].this.args["wrapped"])
+
+ self.assertEqual(expr.sql(), "SELECT * FROM (table)")
+
+ expr = parse_one("select * from (tbl1 join tbl2)")
+ self.assertIsInstance(expr.args["from"].this, exp.Table)
+ self.assertTrue(expr.args["from"].this.args["wrapped"])
+ self.assertEqual(len(expr.args["from"].this.args["joins"]), 1)
+
+ expr = parse_one("select * from (tbl1 join tbl2) t")
+ self.assertIsInstance(expr.args["from"].this, exp.Subquery)
+ self.assertIsInstance(expr.args["from"].this.this, exp.Select)
+ self.assertEqual(expr.sql(), "SELECT * FROM (SELECT * FROM tbl1, tbl2) AS t")
+
+ expr = parse_one("select * from (tbl as tbl) t")
+ self.assertEqual(expr.sql(), "SELECT * FROM (SELECT * FROM tbl AS tbl) AS t")
+
+ expr = parse_one("select * from ((a cross join b) cross join c)")
+ self.assertIsInstance(expr.args["from"].this, exp.Table)
+ self.assertTrue(expr.args["from"].this.args["wrapped"])
+ self.assertEqual(len(expr.args["from"].this.args["joins"]), 2)
+ self.assertEqual(expr.sql(), "SELECT * FROM (a CROSS JOIN b CROSS JOIN c)")
+
+ expr = parse_one("select * from ((a cross join b) cross join c) t")
+ self.assertIsInstance(expr.args["from"].this, exp.Subquery)
+ self.assertEqual(len(expr.args["from"].this.this.args["joins"]), 2)
+ self.assertEqual(
+ expr.sql(), "SELECT * FROM (SELECT * FROM a CROSS JOIN b CROSS JOIN c) AS t"
+ )
+
+ expr = parse_one("select * from (a cross join (b cross join c))")
+ self.assertIsInstance(expr.args["from"].this, exp.Table)
+ self.assertTrue(expr.args["from"].this.args["wrapped"])
+ self.assertEqual(len(expr.args["from"].this.args["joins"]), 1)
+ self.assertIsInstance(expr.args["from"].this.args["joins"][0].this, exp.Table)
+ self.assertTrue(expr.args["from"].this.args["joins"][0].this.args["wrapped"])
+ self.assertEqual(expr.sql(), "SELECT * FROM (a CROSS JOIN (b CROSS JOIN c))")
+
+ expr = parse_one("select * from ((a cross join ((b cross join c) cross join d)))")
+ self.assertEqual(expr.sql(), "SELECT * FROM (a CROSS JOIN (b CROSS JOIN c CROSS JOIN d))")
+
+ expr = parse_one(
+ "select * from ((a cross join ((b cross join c) cross join (d cross join e))))"
+ )
+ self.assertEqual(
+ expr.sql(), "SELECT * FROM (a CROSS JOIN (b CROSS JOIN c CROSS JOIN (d CROSS JOIN e)))"
+ )