summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-08-19 22:19:59 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2018-08-19 22:22:24 -0400
commit3e2f61c439dab76133a49b7a16b03bf4071d4c4c (patch)
tree7d3ba13926308309286bd5ccf9618c4bd22cbd4b /test/sql
parentc3869f23836bd35d5ed565a4b84b4ab70293c0f7 (diff)
downloadsqlalchemy-3e2f61c439dab76133a49b7a16b03bf4071d4c4c.tar.gz
Add missing range_ / rows parameters to additional over() methods
Added missing window function parameters :paramref:`.WithinGroup.over.range_` and :paramref:`.WithinGroup.over.rows` parameters to the :meth:`.WithinGroup.over` and :meth:`.FunctionFilter.over` methods, to correspond to the range/rows feature added to the "over" method of SQL functions as part of :ticket:`3049` in version 1.1. Fixes: #4322 Change-Id: I77dcdac65c699a4b52a3fc3ee09a100ffb4fc20e
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compiler.py44
-rw-r--r--test/sql/test_functions.py32
2 files changed, 76 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 0ef19e0cb..7f2c44bf1 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -2485,6 +2485,50 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
func.row_number().over, range_=(-5, 8), rows=(-2, 5)
)
+ def test_over_within_group(self):
+ from sqlalchemy import within_group
+ stmt = select([
+ table1.c.myid,
+ within_group(
+ func.percentile_cont(0.5),
+ table1.c.name.desc()
+ ).over(
+ range_=(1, 2),
+ partition_by=table1.c.name,
+ order_by=table1.c.myid
+ )
+ ])
+ eq_ignore_whitespace(
+ str(stmt),
+ "SELECT mytable.myid, percentile_cont(:percentile_cont_1) "
+ "WITHIN GROUP (ORDER BY mytable.name DESC) "
+ "OVER (PARTITION BY mytable.name ORDER BY mytable.myid "
+ "RANGE BETWEEN :param_1 FOLLOWING AND :param_2 FOLLOWING) "
+ "AS anon_1 FROM mytable"
+ )
+
+ stmt = select([
+ table1.c.myid,
+ within_group(
+ func.percentile_cont(0.5),
+ table1.c.name.desc()
+ ).over(
+ rows=(1, 2),
+ partition_by=table1.c.name,
+ order_by=table1.c.myid
+ )
+ ])
+ eq_ignore_whitespace(
+ str(stmt),
+ "SELECT mytable.myid, percentile_cont(:percentile_cont_1) "
+ "WITHIN GROUP (ORDER BY mytable.name DESC) "
+ "OVER (PARTITION BY mytable.name ORDER BY mytable.myid "
+ "ROWS BETWEEN :param_1 FOLLOWING AND :param_2 FOLLOWING) "
+ "AS anon_1 FROM mytable"
+ )
+
+
+
def test_date_between(self):
import datetime
table = Table('dt', metadata,
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py
index 3032c3ce3..48d5fc37f 100644
--- a/test/sql/test_functions.py
+++ b/test/sql/test_functions.py
@@ -513,6 +513,38 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
"AS anon_1 FROM mytable"
)
+ def test_funcfilter_windowing_range(self):
+ self.assert_compile(
+ select([
+ func.rank().filter(
+ table1.c.name > 'foo'
+ ).over(
+ range_=(1, 5),
+ partition_by=['description']
+ )
+ ]),
+ "SELECT rank() FILTER (WHERE mytable.name > :name_1) "
+ "OVER (PARTITION BY mytable.description RANGE BETWEEN :param_1 "
+ "FOLLOWING AND :param_2 FOLLOWING) "
+ "AS anon_1 FROM mytable"
+ )
+
+ def test_funcfilter_windowing_rows(self):
+ self.assert_compile(
+ select([
+ func.rank().filter(
+ table1.c.name > 'foo'
+ ).over(
+ rows=(1, 5),
+ partition_by=['description']
+ )
+ ]),
+ "SELECT rank() FILTER (WHERE mytable.name > :name_1) "
+ "OVER (PARTITION BY mytable.description ROWS BETWEEN :param_1 "
+ "FOLLOWING AND :param_2 FOLLOWING) "
+ "AS anon_1 FROM mytable"
+ )
+
def test_funcfilter_within_group(self):
stmt = select([
table1.c.myid,