From 794e2650b7cb504a9492214c9e27005c044526a8 Mon Sep 17 00:00:00 2001 From: Violet Folino Gallo <48537601+galloviolet@users.noreply.github.com> Date: Wed, 16 Jul 2025 12:04:54 -0700 Subject: [PATCH] split into basic and numeric tests --- lib/sqlalchemy/testing/requirements.py | 5 +++ lib/sqlalchemy/testing/suite/test_select.py | 49 ++++++++++++--------- test/requirements.py | 5 +++ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index f0384eb91a..6fbf4786e1 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -1880,3 +1880,8 @@ class SuiteRequirements(Requirements): """Target backend supports custom ESCAPE characters with LIKE comparisons""" return exclusions.open() + + @property + def window_range_numeric(self): + """Target backend supports fractional values in RANGE""" + return exclusions.closed() \ No newline at end of file diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py index 97833149b5..19979ab392 100644 --- a/lib/sqlalchemy/testing/suite/test_select.py +++ b/lib/sqlalchemy/testing/suite/test_select.py @@ -1944,31 +1944,36 @@ class WindowFunctionTest(fixtures.TablesTest): eq_(rows, [(95,) for i in range(19)]) - def test_window_range(self, connection): + def test_window_range_basic(self, connection): some_table = self.tables.some_table - # SQL Server only allows UNBOUNDED and CURRENT ROW in the RANGE clause - if config.db.dialect in ["mssql+aiodbc", "mssql+pymssql", "mssql+pyodbc"]: - rows = connection.execute( - select( - func.max(some_table.c.col1).over( - partition_by=[some_table.c.col2], - order_by=[some_table.c.col2.asc()], - range_=(_FrameClauseType.RANGE_UNBOUNDED, _FrameClauseType.RANGE_CURRENT) - ) + rows = connection.execute( + select( + func.max(some_table.c.col1).over( + partition_by=[some_table.c.col2], + order_by=[some_table.c.col2.asc()], + range_=(0, 1) ) - ) - else: - rows = connection.execute( - select( - func.max(some_table.c.col3).over( - partition_by=[some_table.c.col3], - order_by=[some_table.c.col3.asc()], - range_=(-1.25, 1.25), - ) - ).where(some_table.c.col1 < 20) - ).all() + ).where(some_table.c.col1 < 20) + ).all() + + eq_(rows, [(i,) for i in range(1, 20)]) + + + @testing.requires.window_range_numeric + def test_window_range_numeric(self, connection): + some_table = self.tables.some_table + rows = connection.execute( + select( + func.max(some_table.c.col3).over( + partition_by=[some_table.c.col3], + order_by=[some_table.c.col3.asc()], + range_=(-1.25, 1.25), + ) + ).where(some_table.c.col1 < 20) + ).all() + + eq_(rows, [(i + 0.5,) for i in range(1, 20)]) - eq_(rows, [(i + 1.5,) for i in range(19)]) def test_window_rows_between_w_caching(self, connection): some_table = self.tables.some_table diff --git a/test/requirements.py b/test/requirements.py index 1f4a4eb392..c1a576b220 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -2128,3 +2128,8 @@ class DefaultRequirements(SuiteRequirements): def supports_bitwise_shift(self): """Target database supports bitwise left or right shift""" return fails_on(["oracle"]) + + @property + def window_range_numeric(self): + """Target database supports window functions with fractional RANGE values""" + return fails_on(["mssql"]) \ No newline at end of file -- 2.47.3