diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-27 10:46:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-27 10:46:33 +0000 |
commit | aa1d1f1ea72887a3efb78f4950e27bc79dfa3766 (patch) | |
tree | a9f5bf5ab14c69d011e21d40f8504c4f94a8de72 /tests/test_expressions.py | |
parent | Adding upstream version 11.2.0. (diff) | |
download | sqlglot-aa1d1f1ea72887a3efb78f4950e27bc79dfa3766.tar.xz sqlglot-aa1d1f1ea72887a3efb78f4950e27bc79dfa3766.zip |
Adding upstream version 11.2.3.upstream/11.2.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/test_expressions.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_expressions.py b/tests/test_expressions.py index 8b74fe1..caa419e 100644 --- a/tests/test_expressions.py +++ b/tests/test_expressions.py @@ -91,6 +91,11 @@ class TestExpressions(unittest.TestCase): self.assertIsInstance(column.parent_select, exp.Select) self.assertIsNone(column.find_ancestor(exp.Join)) + def test_root(self): + ast = parse_one("select * from (select a from x)") + self.assertIs(ast, ast.root()) + self.assertIs(ast, ast.find(exp.Column).root()) + def test_alias_or_name(self): expression = parse_one( "SELECT a, b AS B, c + d AS e, *, 'zz', 'zz' AS z FROM foo as bar, baz" @@ -767,3 +772,36 @@ FROM foo""", exp.rename_table("t1", "t2").sql(), "ALTER TABLE t1 RENAME TO t2", ) + + def test_is_star(self): + assert parse_one("*").is_star + assert parse_one("foo.*").is_star + assert parse_one("SELECT * FROM foo").is_star + assert parse_one("(SELECT * FROM foo)").is_star + assert parse_one("SELECT *, 1 FROM foo").is_star + assert parse_one("SELECT foo.* FROM foo").is_star + assert parse_one("SELECT * EXCEPT (a, b) FROM foo").is_star + assert parse_one("SELECT foo.* EXCEPT (foo.a, foo.b) FROM foo").is_star + assert parse_one("SELECT * REPLACE (a AS b, b AS C)").is_star + assert parse_one("SELECT * EXCEPT (a, b) REPLACE (a AS b, b AS C)").is_star + assert parse_one("SELECT * INTO newevent FROM event").is_star + assert parse_one("SELECT * FROM foo UNION SELECT * FROM bar").is_star + assert parse_one("SELECT * FROM bla UNION SELECT 1 AS x").is_star + assert parse_one("SELECT 1 AS x UNION SELECT * FROM bla").is_star + assert parse_one("SELECT 1 AS x UNION SELECT 1 AS x UNION SELECT * FROM foo").is_star + + def test_set_metadata(self): + ast = parse_one("SELECT foo.col FROM foo") + + self.assertIsNone(ast._meta) + + # calling ast.meta would lazily instantiate self._meta + self.assertEqual(ast.meta, {}) + self.assertEqual(ast._meta, {}) + + ast.meta["some_meta_key"] = "some_meta_value" + self.assertEqual(ast.meta.get("some_meta_key"), "some_meta_value") + self.assertEqual(ast.meta.get("some_other_meta_key"), None) + + ast.meta["some_other_meta_key"] = "some_other_meta_value" + self.assertEqual(ast.meta.get("some_other_meta_key"), "some_other_meta_value") |