1
0
Fork 0

Adding upstream version 20.3.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 21:17:33 +01:00
parent 5bd573dda1
commit fd9de5e4cb
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
132 changed files with 55125 additions and 51576 deletions

View file

@ -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"])