Skip to content

Commit dd6de36

Browse files
committed
rename _group_pipline
1 parent 7638442 commit dd6de36

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

django_mongodb/compiler.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SQLCompiler(compiler.SQLCompiler):
2424

2525
def __init__(self, *args, **kwargs):
2626
super().__init__(*args, **kwargs)
27-
self._group_pipeline = None
27+
self.aggregation_pipeline = None
2828

2929
def _get_group_alias_column(self, expr, annotation_group_idx):
3030
"""
@@ -100,7 +100,7 @@ def _prepare_expressions_for_pipeline(self, expression, target, annotation_group
100100
replacements[sub_expr] = replacing_expr
101101
return replacements, group
102102

103-
def _prepare_annotations_for_group_pipeline(self):
103+
def _prepare_annotations_for_aggregation_pipeline(self):
104104
"""Prepare annotations for the MongoDB aggregation pipeline."""
105105
replacements = {}
106106
group = {}
@@ -157,7 +157,7 @@ def _get_group_id_expressions(self, order_by):
157157

158158
return ids, replacements
159159

160-
def _build_group_pipeline(self, ids, group):
160+
def _build_aggregation_pipeline(self, ids, group):
161161
"""Build the aggregation pipeline for grouping."""
162162
pipeline = []
163163
if not ids:
@@ -196,15 +196,15 @@ def _build_group_pipeline(self, ids, group):
196196

197197
def pre_sql_setup(self, with_col_aliases=False):
198198
extra_select, order_by, group_by = super().pre_sql_setup(with_col_aliases=with_col_aliases)
199-
group, all_replacements = self._prepare_annotations_for_group_pipeline()
199+
group, all_replacements = self._prepare_annotations_for_aggregation_pipeline()
200200
# query.group_by is either:
201201
# - None: no GROUP BY
202202
# - True: group by select fields
203203
# - a list of expressions to group by.
204204
if group or self.query.group_by:
205205
ids, replacements = self._get_group_id_expressions(order_by)
206206
all_replacements.update(replacements)
207-
pipeline = self._build_group_pipeline(ids, group)
207+
pipeline = self._build_aggregation_pipeline(ids, group)
208208
if self.having:
209209
pipeline.append(
210210
{
@@ -215,7 +215,7 @@ def pre_sql_setup(self, with_col_aliases=False):
215215
}
216216
}
217217
)
218-
self._group_pipeline = pipeline
218+
self.aggregation_pipeline = pipeline
219219

220220
self.annotations = {
221221
target: expr.replace_expressions(all_replacements)
@@ -342,7 +342,7 @@ def build_query(self, columns=None):
342342
"""Check if the query is supported and prepare a MongoQuery."""
343343
self.check_query()
344344
query = self.query_class(self)
345-
query.aggregation_pipeline = self.get_aggregation_pipeline()
345+
query.aggregation_pipeline = self.aggregation_pipeline
346346
query.lookup_pipeline = self.get_lookup_pipeline()
347347
query.order_by(self._get_ordering())
348348
query.project_fields = self.get_project_fields(columns, ordering=query.ordering)
@@ -461,9 +461,6 @@ def _get_aggregate_expressions(self, expr):
461461
elif hasattr(expr, "get_source_expressions"):
462462
stack.extend(expr.get_source_expressions())
463463

464-
def get_aggregation_pipeline(self):
465-
return self._group_pipeline
466-
467464
def get_project_fields(self, columns=None, ordering=None):
468465
fields = {}
469466
for name, expr in columns or []:
@@ -613,22 +610,20 @@ class SQLAggregateCompiler(SQLCompiler):
613610
def build_query(self, columns=None):
614611
query = self.query_class(self)
615612
query.project_fields = self.get_project_fields(tuple(self.annotations.items()))
616-
query.aggregation_pipeline = self.get_aggregation_pipeline()
613+
query.aggregation_pipeline = self.aggregation_pipeline
617614

618615
compiler = self.query.inner_query.get_compiler(
619616
self.using,
620617
elide_empty=self.elide_empty,
621618
)
622619
compiler.pre_sql_setup(with_col_aliases=False)
620+
# Avoid $project (columns=None) if unneeded.
623621
columns = (
624622
compiler.get_columns()
625623
if compiler.query.annotations or not compiler.query.default_cols
626624
else None
627625
)
628-
subquery = compiler.build_query(
629-
# Avoid $project (columns=None) if unneeded.
630-
columns
631-
)
626+
subquery = compiler.build_query(columns)
632627
query.subquery = subquery
633628
return query
634629

0 commit comments

Comments
 (0)