summaryrefslogtreecommitdiffstats
path: root/tests/test_parser.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-19 11:01:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-19 11:01:36 +0000
commit948a422be120c069e48c63a8770fec7204307897 (patch)
tree80bc02d5e6cd3527409386aa1d706272bea54e6c /tests/test_parser.py
parentAdding upstream version 20.1.0. (diff)
downloadsqlglot-948a422be120c069e48c63a8770fec7204307897.tar.xz
sqlglot-948a422be120c069e48c63a8770fec7204307897.zip
Adding upstream version 20.3.0.upstream/20.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.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py
index f3e663e..6611b87 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -17,6 +17,13 @@ class TestParser(unittest.TestCase):
self.assertIsInstance(parse_one("int", into=exp.DataType), exp.DataType)
self.assertIsInstance(parse_one("array<int>", into=exp.DataType), exp.DataType)
self.assertIsInstance(parse_one("foo", into=exp.Table), exp.Table)
+ self.assertIsInstance(
+ parse_one(
+ "WHEN MATCHED THEN UPDATE SET target.salary = COALESCE(source.salary, target.salary)",
+ into=exp.When,
+ ),
+ exp.When,
+ )
with self.assertRaises(ParseError) as ctx:
parse_one("SELECT * FROM tbl", into=exp.Table)
@@ -94,12 +101,31 @@ class TestParser(unittest.TestCase):
tables = [t.sql() for t in parse_one("select * from a, b.c, .d").find_all(exp.Table)]
self.assertEqual(set(tables), {"a", "b.c", "d"})
- def test_union_order(self):
+ def test_union(self):
self.assertIsInstance(parse_one("SELECT * FROM (SELECT 1) UNION SELECT 2"), exp.Union)
self.assertIsInstance(
parse_one("SELECT x FROM y HAVING x > (SELECT 1) UNION SELECT 2"), exp.Union
)
+ # Check that modifiers are attached to the topmost union node and not the rightmost query
+ single_union = "SELECT x FROM t1 UNION ALL SELECT x FROM t2 LIMIT 1"
+ expr = parse_one(single_union)
+ limit = expr.assert_is(exp.Union).args.get("limit")
+ self.assertIsInstance(limit, exp.Limit)
+ self.assertEqual(expr.sql(), single_union)
+
+ two_unions = (
+ "SELECT x FROM t1 UNION ALL SELECT x FROM t2 UNION ALL SELECT x FROM t3 LIMIT 1"
+ )
+ expr = parse_one(two_unions)
+ limit = expr.assert_is(exp.Union).args.get("limit")
+ self.assertIsInstance(limit, exp.Limit)
+ self.assertEqual(expr.sql(), two_unions)
+
+ expr = parse_one(single_union, read="clickhouse")
+ self.assertIsNone(expr.args.get("limit"))
+ self.assertEqual(expr.sql(dialect="clickhouse"), single_union)
+
def test_select(self):
self.assertIsNotNone(parse_one("select 1 natural"))
self.assertIsNotNone(parse_one("select * from (select 1) x order by x.y").args["order"])