summaryrefslogtreecommitdiffstats
path: root/tests/test_expressions.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-10-10 11:29:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-10-10 11:29:05 +0000
commitf818ab3b896d52e874634b7c4db3533078c1887f (patch)
tree8d0f7e4b7f165f33f49da74cb34eb31a0a2d147b /tests/test_expressions.py
parentReleasing debian version 6.2.8-1. (diff)
downloadsqlglot-f818ab3b896d52e874634b7c4db3533078c1887f.tar.xz
sqlglot-f818ab3b896d52e874634b7c4db3533078c1887f.zip
Merging upstream version 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"],
+ )