climate_ref.models.dataset_query
#
Query builder for the polymorphic Dataset hierarchy.
select_datasets
is the cononical definition for selecting datasets consistently.
It backs both climate_ref.datasets (DatasetAdapter.load_catalog) and
the climate_ref.results read layer (reader.datasets), so the two cannot drift apart.
DatasetFilter
#
Declarative filter over datasets.
source_type is required.
It selects which which facet columns the query can target.
This limits our filtering to a single source type at a time to ensure that the files can be
collapsed into a dataframe.
Every other field is optional with None meaning "do not constrain on this axis".
Source code in packages/climate-ref/src/climate_ref/models/dataset_query.py
include_retracted = False
class-attribute
instance-attribute
#
Whether retracted datasets (Dataset.retracted_at is not None) are included.
Defaults to False so an unqualified query matches solve-time eligibility.
Provenance, history and inspection reads (e.g. ref datasets list) pass True explicitly.
select_datasets(filter, *, latest_group_by=None)
#
Build the Select over the Dataset subclass for the given filter.
Any limit is deliberately not applied here. Callers should apply limits after filtering out superseded versions.
Retracted datasets (retracted_at is not None) are excluded unless filter.include_retracted is set,
applied before the latest_only window so a retracted row never wins a latest-version tie either.
latest_group_by is the adapter's dataset_id_metadata,
which is used as the partition columns for the latest-version window.
It is passed in rather than looked up here because select_datasets lives in the models layer
and must not import the adapter registry, so it cannot resolve it itself; callers pass it through.
latest_group_by is required whenever filter.latest_only is True (the default):
passing latest_only=True without it raises ValueError rather than silently returning an
un-deduplicated result.
When both are set, rows are deduplicated with a
RANK() OVER (PARTITION BY <latest_group_by> ORDER BY version_key DESC) window
(applied after all other filters/joins),
keeping every row tied at the maximum version_key -- so ties are not silently dropped.
Set latest_only=False to list every version; latest_group_by is then ignored.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/climate-ref/src/climate_ref/models/dataset_query.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |