summaryrefslogtreecommitdiffstats
path: root/tests/test_transforms.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-30 05:07:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-09-30 05:07:13 +0000
commit276f5723c8ab7e0b2938693db546dbd30be3f01a (patch)
treee6294c63de34a03e373245ec4cb1efbca1edfe61 /tests/test_transforms.py
parentAdding upstream version 6.2.1. (diff)
downloadsqlglot-276f5723c8ab7e0b2938693db546dbd30be3f01a.tar.xz
sqlglot-276f5723c8ab7e0b2938693db546dbd30be3f01a.zip
Adding upstream version 6.2.6.upstream/6.2.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_transforms.py')
-rw-r--r--tests/test_transforms.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/tests/test_transforms.py b/tests/test_transforms.py
index 2030109..1928d2c 100644
--- a/tests/test_transforms.py
+++ b/tests/test_transforms.py
@@ -6,11 +6,32 @@ from sqlglot.transforms import unalias_group
class TestTime(unittest.TestCase):
def validate(self, transform, sql, target):
- self.assertEqual(parse_one(sql).transform(transform).sql(), target)
+ with self.subTest(sql):
+ self.assertEqual(parse_one(sql).transform(transform).sql(), target)
def test_unalias_group(self):
self.validate(
unalias_group,
"SELECT a, b AS b, c AS c, 4 FROM x GROUP BY a, b, x.c, 4",
- "SELECT a, b AS b, c AS c, 4 FROM x GROUP BY a, 2, x.c, 4",
+ "SELECT a, b AS b, c AS c, 4 FROM x GROUP BY a, b, x.c, 4",
+ )
+ self.validate(
+ unalias_group,
+ "SELECT TO_DATE(the_date) AS the_date, CUSTOM_UDF(other_col) AS other_col, last_col AS aliased_last, COUNT(*) AS the_count FROM x GROUP BY TO_DATE(the_date), CUSTOM_UDF(other_col), aliased_last",
+ "SELECT TO_DATE(the_date) AS the_date, CUSTOM_UDF(other_col) AS other_col, last_col AS aliased_last, COUNT(*) AS the_count FROM x GROUP BY TO_DATE(the_date), CUSTOM_UDF(other_col), 3",
+ )
+ self.validate(
+ unalias_group,
+ "SELECT SOME_UDF(TO_DATE(the_date)) AS the_date, COUNT(*) AS the_count FROM x GROUP BY SOME_UDF(TO_DATE(the_date))",
+ "SELECT SOME_UDF(TO_DATE(the_date)) AS the_date, COUNT(*) AS the_count FROM x GROUP BY SOME_UDF(TO_DATE(the_date))",
+ )
+ self.validate(
+ unalias_group,
+ "SELECT SOME_UDF(TO_DATE(the_date)) AS new_date, COUNT(*) AS the_count FROM x GROUP BY new_date",
+ "SELECT SOME_UDF(TO_DATE(the_date)) AS new_date, COUNT(*) AS the_count FROM x GROUP BY 1",
+ )
+ self.validate(
+ unalias_group,
+ "SELECT the_date AS the_date, COUNT(*) AS the_count FROM x GROUP BY the_date",
+ "SELECT the_date AS the_date, COUNT(*) AS the_count FROM x GROUP BY the_date",
)