Skip to content

Analysis Nodes

Dave Lawrence edited this page Feb 24, 2022 · 4 revisions

For a quick overview of how the node filters work, see ASMR Poster

node annotation kwargs

Nodes can return a dict of kwargs that are passed to Django queryset.annotate() - this is so you can setup FilteredRelations etc, controlling how you join to another table (eg to restrict it to just 1 PostGres partition)

node Q objects

Nodes perform filtering by returning a Django Q object - these represent SQL operations, and can be combined easily via AND and OR operations.

Applying annotation/filters in different orders can cause multiple joins to the same table (even when using FilteredRelation) - so the node Qs are stored in a dictionary, with keys being the node annotation kwargs. There are applied in the order of annotation kwargs.

Chains of filters to a reverse foreign key relationship causes multiple joins, so use Q objects which are combined at the end

qs = qs.filter(table_1__val=1)
qs = qs.filter(table_2__val=2)

is not necessarily equal to:

qs.filter(table_1__val=1, table_2__val=2)
Clone this wiki locally