|
1 |
| -from django.db.models.aggregates import Aggregate, Count, StdDev, Variance |
| 1 | +from django.db.models.aggregates import ( |
| 2 | + Aggregate, |
| 3 | + AggregateFilter, |
| 4 | + Count, |
| 5 | + StdDev, |
| 6 | + StringAgg, |
| 7 | + Variance, |
| 8 | +) |
2 | 9 | from django.db.models.expressions import Case, Value, When
|
3 | 10 | from django.db.models.lookups import IsNull
|
4 | 11 |
|
@@ -31,6 +38,10 @@ def aggregate(
|
31 | 38 | return {f"${operator}": lhs_mql}
|
32 | 39 |
|
33 | 40 |
|
| 41 | +def aggregate_filter(self, compiler, connection, **extra_context): |
| 42 | + return self.condition.as_mql(compiler, connection, **extra_context) |
| 43 | + |
| 44 | + |
34 | 45 | def count(self, compiler, connection, resolve_inner_expression=False, **extra_context): # noqa: ARG001
|
35 | 46 | """
|
36 | 47 | When resolve_inner_expression=True, return the MQL that resolves as a
|
@@ -72,8 +83,16 @@ def stddev_variance(self, compiler, connection, **extra_context):
|
72 | 83 | return aggregate(self, compiler, connection, operator=operator, **extra_context)
|
73 | 84 |
|
74 | 85 |
|
| 86 | +def string_agg(self, compiler, connection, **extra_context): # # noqa: ARG001 |
| 87 | + from django.db import NotSupportedError |
| 88 | + |
| 89 | + raise NotSupportedError("StringAgg is not supported.") |
| 90 | + |
| 91 | + |
75 | 92 | def register_aggregates():
|
76 | 93 | Aggregate.as_mql = aggregate
|
| 94 | + AggregateFilter.as_mql = aggregate_filter |
77 | 95 | Count.as_mql = count
|
78 | 96 | StdDev.as_mql = stddev_variance
|
| 97 | + StringAgg.as_mql = string_agg |
79 | 98 | Variance.as_mql = stddev_variance
|
0 commit comments