summaryrefslogtreecommitdiffstats
path: root/tests/test_expressions.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-10-10 11:29:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-10-10 11:29:00 +0000
commit74b38d30f43f7005428e09fa80508c5f21324c99 (patch)
tree7a0d4e49fffdc0330fc941c6528d3c8669a2acc6 /tests/test_expressions.py
parentAdding upstream version 6.2.8. (diff)
downloadsqlglot-74b38d30f43f7005428e09fa80508c5f21324c99.tar.xz
sqlglot-74b38d30f43f7005428e09fa80508c5f21324c99.zip
Adding upstream version 6.3.1.upstream/6.3.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_expressions.py')
-rw-r--r--tests/test_expressions.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_expressions.py b/tests/test_expressions.py
index cc41307..abc95cb 100644
--- a/tests/test_expressions.py
+++ b/tests/test_expressions.py
@@ -115,6 +115,21 @@ class TestExpressions(unittest.TestCase):
["first", "second", "third"],
)
+ def test_table_name(self):
+ self.assertEqual(exp.table_name(parse_one("a", into=exp.Table)), "a")
+ self.assertEqual(exp.table_name(parse_one("a.b", into=exp.Table)), "a.b")
+ self.assertEqual(exp.table_name(parse_one("a.b.c", into=exp.Table)), "a.b.c")
+ self.assertEqual(exp.table_name("a.b.c"), "a.b.c")
+
+ def test_replace_tables(self):
+ self.assertEqual(
+ exp.replace_tables(
+ parse_one("select * from a join b join c.a join d.a join e.a"),
+ {"a": "a1", "b": "b.a", "c.a": "c.a2", "d.a": "d2"},
+ ).sql(),
+ 'SELECT * FROM "a1" JOIN "b"."a" JOIN "c"."a2" JOIN "d2" JOIN e.a',
+ )
+
def test_named_selects(self):
expression = parse_one("SELECT a, b AS B, c + d AS e, *, 'zz', 'zz' AS z FROM foo as bar, baz")
self.assertEqual(expression.named_selects, ["a", "B", "e", "*", "zz", "z"])
@@ -474,3 +489,10 @@ class TestExpressions(unittest.TestCase):
]:
with self.subTest(value):
self.assertEqual(exp.convert(value).sql(), expected)
+
+ def test_annotation_alias(self):
+ expression = parse_one("SELECT a, b AS B, c #comment, d AS D #another_comment FROM foo")
+ self.assertEqual(
+ [e.alias_or_name for e in expression.expressions],
+ ["a", "B", "c", "D"],
+ )