Repository navigation
feat(locations): Composite location support - #221
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A minor comment typo remains flagged as an active finding, leaving the change with unresolved issues.
1 open issue
What changed in this PR
This PR adds composite location support to the data platform. A composite location is defined as a weighted linear sum of other ("component") locations. The change is primarily on the read path: loc.sources_mv is redefined to compute composite capacities/metadata, and the observation and prediction read queries are rewritten to combine a direct read (values written straight to the location) with a composite read (weighted aggregation of component values computed on the fly), preferring the direct/freshest result. It also adds management RPCs to configure components and delete locations, surfacing is_composite through the API. This realizes the GSP reconstruction use case from issue #220.
Changes:
- New
loc.geometry_componentstable + nesting-prevention trigger, and a rewrittenloc.sources_mvmaterialized view that unions physical and composite sources (migration00019). - Rewritten
observations.sql/predictions.sqlread queries to aggregate component values (weighted by capacity) with strict all-or-nothing completeness and quantile null-safety. - New
SetLocationComponentsandDeleteLocationRPCs (+is_compositeonGetLocation/ListLocations), implemented in the postgres and dummy servers with extensive integration tests.
| File | Description |
|---|---|
proto/ocf/dp/dp-data.service.proto |
Adds SetLocationComponents and DeleteLocation RPCs. |
proto/ocf/dp/dp-data.messages.proto |
Adds component messages and is_composite fields. |
internal/server/postgres/sql/migrations/00019_virtual_geometries.sql |
New components table, trigger, and composite-aware sources_mv. |
internal/server/postgres/sql/migrations/00018_*.sql |
Folds price tables into consolidated schema (removes standalone file). |
internal/server/postgres/sql/queries/observations.sql |
Composite-aware observation reads (window, latest, at-time). |
internal/server/postgres/sql/queries/predictions.sql |
Composite-aware prediction reads; comment typos. |
internal/server/postgres/sql/queries/locations.sql |
Component CRUD queries; GetSourceHistory now reads sources_mv. |
internal/server/postgres/sql/.sqlfluff.toml |
Raises large-file byte limit for bigger queries. |
internal/server/postgres/dataserverimpl.go |
Implements new RPCs + unpackLocationComponents. |
internal/server/postgres/mappers.go / mappers_test.go |
Propagates is_composite in location summaries. |
internal/server/postgres/dataserverimpl_test.go |
Extensive composite CRUD/temporal/math integration tests. |
internal/server/dummy/dataserverimpl.go / _test.go |
Stub implementations + tests for the new RPCs. |
Review effort: Balanced
| ), | ||
| aggregated AS ( | ||
| /* Aggregate the winning predictions for each target time across all components via weighted sum | ||
| * There is less oging on here than it looks, it's just repeated logic for each p-level. |

This enables composite locations.
A composite location is a location that is made up of a weighted linear sum of other locations. It has the following requirements:
This PR enables this feature by modifying the read path.
There are now two components to a read query: the direct read, and the composite read. If a geometry is not marked as a composite, then only the direct path is used, and queries continue as previously. In the case of a composite however, every read query goes down two paths: the direct read, and the composite read. The results of these two are combined to create one resultant data set.
Contribution Checklist
make lintwith your changes locally?make testwith your changes locally?Warning
PRs may be closed if all the above boxes are not checked.
Closes #220