Run a top-K aggregation and write the ranked rows (Step 3 of #386) - #494
Open
zipdoki wants to merge 5 commits into
Open
Run a top-K aggregation and write the ranked rows (Step 3 of #386)#494zipdoki wants to merge 5 commits into
zipdoki wants to merge 5 commits into
Conversation
1 task
zipdoki
force-pushed
the
feat/topk-aggregate
branch
from
August 19, 2026 08:18
59beb1e to
37e1c4b
Compare
zipdoki
force-pushed
the
feat/topk-aggregate
branch
from
August 20, 2026 02:14
37e1c4b to
7af6396
Compare
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A group can declare a top-K, but nothing computes one. The declaration sits in metadata and no ranked row is ever written. This runs the aggregation.
TopkAggregationHandlerscans the source group with the declaration'srangesinterpolated against the event, sumsmetricper(entity, dimension key), and writes rank rows keyed byrankSource(...)under themetric_descindex. When a declaration is a sliding window andrefreshAfterMillis > 0, it also schedules a refreshfor the instant the bucket leaves the window. Consuming that refresh message is the next PR in the stack.
POST /aggregations/v1/aggregatedrives it, taking a batch of edges:{ "items": [ { "database": "graph", "table": "likes", "edge": { "source": "...", "target": "...", "...": "..." } } ] }{ "items": [ { "database": "graph", "table": "likes", "source": "...", "target": "...", "status": "OK", "error": null } ] }Status and error are reported per item, so one bad edge does not sink the rest of the batch.
Two bucket changes ride along because the window math depends on them.
Bucketnow has a test pinning how a date bucket rounds both a value and a range bound, which the refresh schedule reads directly, and its format precision is read in one place instead of being re-derived at each call site. Separately, rank keys escape|sotwo rankings can never collide on one row.
Stacked on #493 — that needs to land first.
Part of #386.
Test plan
./gradlew :core:test --tests '*BucketTest*'— date bucket rounding for values and for range bounds./gradlew :core:test --tests '*AggregationConstantsTest*'— rank key composition and|escaping./gradlew :engine:test --tests '*RankingInputsTest*'—rangesinterpolation, entity and dimension resolution./gradlew :engine:test --tests '*TopkAggregationHandlerTest*'— aggregation over the source group, rank row writes, refresh scheduling./gradlew :server:test --tests '*MetadataAggControllerE2ETest*'—POST /aggregations/v1/aggregateover HTTP./gradlew spotlessKotlinCheck build— formatting and full buildAI Assistance