summaryrefslogtreecommitdiffstats
path: root/tests/test_transforms.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-12-02 09:16:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-12-02 09:16:29 +0000
commit1a60bbae98d3b530924a6807a55f8250de19ea86 (patch)
tree87d3000f271a6604fff43db188731229aed918a8 /tests/test_transforms.py
parentAdding upstream version 10.0.8. (diff)
downloadsqlglot-1a60bbae98d3b530924a6807a55f8250de19ea86.tar.xz
sqlglot-1a60bbae98d3b530924a6807a55f8250de19ea86.zip
Adding upstream version 10.1.3.upstream/10.1.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_transforms.py')
-rw-r--r--tests/test_transforms.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/test_transforms.py b/tests/test_transforms.py
index 1928d2c..0bcd2ca 100644
--- a/tests/test_transforms.py
+++ b/tests/test_transforms.py
@@ -1,7 +1,7 @@
import unittest
from sqlglot import parse_one
-from sqlglot.transforms import unalias_group
+from sqlglot.transforms import eliminate_distinct_on, unalias_group
class TestTime(unittest.TestCase):
@@ -35,3 +35,30 @@ class TestTime(unittest.TestCase):
"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",
)
+
+ def test_eliminate_distinct_on(self):
+ self.validate(
+ eliminate_distinct_on,
+ "SELECT DISTINCT ON (a) a, b FROM x ORDER BY c DESC",
+ 'SELECT a, b FROM (SELECT a, b, ROW_NUMBER() OVER (PARTITION BY a ORDER BY c DESC) AS "_row_number" FROM x) WHERE "_row_number" = 1',
+ )
+ self.validate(
+ eliminate_distinct_on,
+ "SELECT DISTINCT ON (a) a, b FROM x",
+ 'SELECT a, b FROM (SELECT a, b, ROW_NUMBER() OVER (PARTITION BY a) AS "_row_number" FROM x) WHERE "_row_number" = 1',
+ )
+ self.validate(
+ eliminate_distinct_on,
+ "SELECT DISTINCT ON (a, b) a, b FROM x ORDER BY c DESC",
+ 'SELECT a, b FROM (SELECT a, b, ROW_NUMBER() OVER (PARTITION BY a, b ORDER BY c DESC) AS "_row_number" FROM x) WHERE "_row_number" = 1',
+ )
+ self.validate(
+ eliminate_distinct_on,
+ "SELECT DISTINCT a, b FROM x ORDER BY c DESC",
+ "SELECT DISTINCT a, b FROM x ORDER BY c DESC",
+ )
+ self.validate(
+ eliminate_distinct_on,
+ "SELECT DISTINCT ON (_row_number) _row_number FROM x ORDER BY c DESC",
+ 'SELECT _row_number FROM (SELECT _row_number, ROW_NUMBER() OVER (PARTITION BY _row_number ORDER BY c DESC) AS "_row_number_2" FROM x) WHERE "_row_number_2" = 1',
+ )