Skip to content

feat(locations): Composite location support - #221

Merged
devsjc merged 5 commits into
mainfrom
devsjc/virtual-locations
Nov 2, 2026
Merged

devsjc merged 5 commits into
mainfrom
devsjc/virtual-locations

Conversation

@devsjc

@devsjc devsjc commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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:

  • Observations and forecasts should be able to be read from a composite location that are calculated on the fly from its components where direct observation values do not exist. Read queries should combine results from both direct +_ composite sources
  • Observations and forecasts should still be able to be written to a composite location directly

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

  • Have you followed the Open Climate Fix Contribution Guidelines?
  • Have you referenced the Issue this PR addresses, where applicable?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added a summary of the changes?
  • Have you written new tests for your changes, where applicable?
  • Have you successfully run make lint with your changes locally?
  • Have you successfully run make test with your changes locally?

Warning

PRs may be closed if all the above boxes are not checked.

Closes #220

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_components table + nesting-prevention trigger, and a rewritten loc.sources_mv materialized view that unions physical and composite sources (migration 00019).
  • Rewritten observations.sql / predictions.sql read queries to aggregate component values (weighted by capacity) with strict all-or-nothing completeness and quantile null-safety.
  • New SetLocationComponents and DeleteLocation RPCs (+ is_composite on GetLocation/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.
@devsjc
devsjc merged commit 359bcdd into main Nov 2, 2026
4 checks passed
@devsjc
devsjc deleted the devsjc/virtual-locations branch November 2, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconstruct GSPs in DP

2 participants