Commit Graph

34 Commits

Author SHA1 Message Date
Simon Charette e16d0c176e Fixed #35064 -- Fixed Window(order_by) crash with DecimalFields on SQLite.
This avoids cast of Window(order_by) for DecimalFields on SQLite.

This was achieved by piggy-backing ExpressionList which already
implements a specialized as_sqlite() method to override the inherited
behaviour of Func through SQLiteNumericMixin.

Refs #31723.

Thanks Quoates for the report.
2023-12-29 09:07:31 +01:00
Simon Charette e76cc93b01
Fixed #34987 -- Fixed queryset crash when mixing aggregate and window annotations.
Regression in f387d024fc.

Just like `OrderByList` the `ExpressionList` expression used to wrap
`Window.partition_by` must implement `get_group_by_cols` to ensure the
necessary grouping when mixing window expressions with aggregate
annotations is performed against the partition members and not the
partition expression itself.

This is necessary because while `partition_by` is implemented as
a source expression of `Window` it's actually a fragment of the WINDOW
expression at the SQL level and thus it should result in a group by its
members and not the sum of them.

Thanks ElRoberto538 for the report.
2023-11-23 06:09:08 +01:00
Sarah Boyce e4d012ca05 Refs #29850 -- Added exclusion support to window frames. 2023-10-30 12:04:55 +01:00
Sarah Boyce 6375cee490 Refs #29850 -- Added RowRange support for positive integer start and negative integer end. 2023-10-28 15:16:07 +02:00
Simon Charette c67ea79aa9 Fixed #34368 -- Made subquery raise NotSupportedError when referencing outer window expression.
Regression in f387d024fc.

Co-authored-by: Jannis Vajen <jvajen@gmail.com>
2023-02-27 07:18:58 +01:00
Simon Charette a9d2d8d1c3 Refs #28477 -- Reduced complexity of aggregation over qualify queries. 2022-11-11 08:46:08 +01:00
Gregor Gärtner f0c06f8ab7 Refs #33990 -- Renamed TransactionTestCase.assertQuerysetEqual() to assertQuerySetEqual().
Co-Authored-By: Michael Howitz <mh@gocept.com>
2022-10-08 08:07:38 +02:00
Mariusz Felisiak f210de760b
Refs #28333 -- Fixed NonQueryWindowTests.test_invalid_filter() on databases that don't support window expressions. 2022-08-29 09:14:56 +02:00
Simon Charette f387d024fc Refs #28333 -- Added partial support for filtering against window functions.
Adds support for joint predicates against window annotations through
subquery wrapping while maintaining errors for disjointed filter
attempts.

The "qualify" wording was used to refer to predicates against window
annotations as it's the name of a specialized Snowflake extension to
SQL that is to window functions what HAVING is to aggregates.

While not complete the implementation should cover most of the common
use cases for filtering against window functions without requiring
the complex subquery pushdown and predicate re-aliasing machinery to
deal with disjointed predicates against columns, aggregates, and window
functions.

A complete disjointed filtering implementation should likely be
deferred until proper QUALIFY support lands or the ORM gains a proper
subquery pushdown interface.
2022-08-15 08:26:26 +02:00
Mariusz Felisiak 7119f40c98 Refs #33476 -- Refactored code to strictly match 88 characters line length. 2022-02-07 20:37:05 +01:00
django-bot 9c19aff7c7 Refs #33476 -- Reformatted code with Black. 2022-02-07 20:37:05 +01:00
Simon Charette aec71aaa5b Fixed #33304 -- Allowed passing string expressions to Window(order_by). 2021-11-23 07:58:44 +01:00
Hasan Ramezani 275dd4ebba
Fixed #32178 -- Allowed database backends to skip tests and mark expected failures.
Co-authored-by: Tim Graham <timograham@gmail.com>
2020-12-10 18:00:57 +01:00
Ian Foote 8b040e3cbb Fixed #25534, Fixed #31639 -- Added support for transform references in expressions.
Thanks Mariusz Felisiak and Simon Charette for reviews.
2020-11-27 20:42:04 +01:00
Mariusz Felisiak 7bfdd3b951 Refs #32096 -- Added test for window expressions with JSONField key transforms. 2020-10-14 20:56:04 +02:00
Hasan Ramezani 71d10ca8c9 Fixed #31723 -- Fixed window functions crash with DecimalField on SQLite.
Thanks Simon Charette for the initial patch.
2020-09-23 09:35:32 +02:00
Mariusz Felisiak 555e3a848e
Removed unused __str__() methods in tests models.
Follow up to 6461583b6c.
2020-04-30 09:13:23 +02:00
Nick Pope 335c9c94ac Simplified imports from django.db and django.contrib.gis.db. 2020-02-04 13:20:06 +01:00
Christopher G Johnson 33ec01caaf Refs #29095 -- Added test for using QuerySet.count() with window expressions ordered by related fields.
Fixed in 3f32154f40.
2020-01-21 10:43:21 +01:00
Tim Graham 227d0c7365 Fixed #31183 -- Added a feature flag for "<db> only supports UNBOUNDED together with PRECEDING and FOLLOWING". 2020-01-20 20:03:35 +01:00
Alex Aktsipetrov bf12273db4 Fixed #31060 -- Reallowed window expressions to be used in conditions outside of queryset filters.
Regression in 4edad1ddf6.

Thanks utapyngo for the report.
2019-12-06 13:52:16 +01:00
Tim Graham 9100c664db Relaxed some query ordering assertions in tests.
It accounts for differences seen on cockroachdb.
2019-11-18 12:32:37 +01:00
aaktsipetrov 4edad1ddf6 Fixed #30668 -- Made QuerySet.filter() raise NotSupportedError if any of source expressions is not filterable. 2019-08-02 15:06:00 +02:00
Mariusz Felisiak 8c5649bfb7
Fixed NonQueryWindowTests.test_unsupported_backend() on MySQL. 2019-05-03 13:49:02 +02:00
Hasan Ramezani 741ce81a42 Fixed #29619 -- Added field names to some FieldErrors. 2019-02-14 18:58:08 -05:00
Simon Charette b8c48d06fa Refs #26608 -- Added a database feature for fixed frame range distance support. 2019-02-09 08:47:41 -05:00
Simon Charette 64d5bafbc6 Fixed #30027 -- Errored out on Window function usage if unsupported. 2019-02-09 08:47:41 -05:00
Simon Charette ebd2fe1861 Refs #30027 -- Enabled window function tests on SQLite 3.25+. 2019-02-09 08:47:40 -05:00
Mariusz Felisiak e49ab72637
Refs #29851 -- Fixed test_subquery_row_range_rank() crash on MariaDB 10.2+.
Thanks Tom Forbes for the report.
2019-01-03 20:18:45 +01:00
Mariusz Felisiak dd8ed64113
Fixed #29851 -- Fixed crash of annotations with window expressions in Subquery. 2018-12-27 20:21:57 +01:00
Florian Apolloner c53af56613 Fixed #29847 -- Ensured proper ordering in queries.
Even though good databases tend to keep the result sorted by the/one
window expression and the planners are smart enough to not resort if not
required, it is not valid to rely on this.

MariaDB specifically did return whatever order it wanted, which is
completely okay. Now we sort towards the expected data for all databases.
2018-10-21 22:05:06 +02:00
Tom Forbes 4198445afc Refs #29548 -- Fixed failing window tests on MariaDB 10.3. 2018-07-30 19:54:56 -04:00
Tomáš Ehrlich fa352626c2 Fixed #29172 -- Fixed crash with Window expression in a subquery. 2018-03-01 10:24:14 -05:00
Mads Jensen d549b88050 Fixed #26608 -- Added support for window expressions (OVER clause).
Thanks Josh Smeaton, Mariusz Felisiak, Sergey Fedoseev, Simon Charettes,
Adam Chainz/Johnson and Tim Graham for comments and reviews and Jamie
Cockburn for initial patch.
2017-09-18 09:42:29 -04:00