Skip to content

Support __count__ sentinel in AGG view to delegate to native COUNT query - #387

Merged
em3s merged 3 commits into
mainfrom
feat/agg-count-sentinel
Jul 2, 2026
Merged

em3s merged 3 commits into
mainfrom
feat/agg-count-sentinel

Conversation

@eazyhozy

@eazyhozy eazyhozy commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Add __count__ as a reserved sentinel group name in the AGG endpoint (GET .../edges/agg/{group}). When the group is __count__, the request is internally delegated to the existing native edge-count query instead of looking up a pre-defined aggregation group in table metadata.

Part of #369

Changes

  • core/.../Constants.kt — add Constants.Group.COUNT_SENTINEL = "__count__" alongside the existing reserved-marker convention (VERTEX_MARKER)
  • engine/.../service/QueryService.kt — detect __count__ in agg(), delegate to counts() (native HBase counter path), and map DataFrameEdgeCountPayload → DataFrameEdgeAggPayload (count field → value field). Add require(ranges == null) guard for the sentinel path. Make ranges nullable; non-sentinel groups enforce non-null via requireNotNull.
  • server/.../EdgeQueryController.kt — make @RequestParam ranges nullable (default null) so callers can omit it when using __count__
  • server/.../EdgeAggCountSentinelE2ETest.kt — 5 E2E test cases (first E2E coverage for the /edges/agg/{group} endpoint):
    • OUT/IN count: asserts start, direction, and value fields; value is compared against /edges/count as ground truth so the two paths are verified to be consistent
    • Multi-start: asserts per-node value for each start key
    • ranges + __count__ → 400
    • Real schema group (by_category) without ranges → 400 (exercises the requireNotNull(ranges) path)

TableBinding interface is unchanged — all binding implementations benefit automatically.

How to Test

./gradlew :server:test --tests "*.EdgeAggCountSentinelE2ETest"

Or end-to-end against a running server:

# Create a table, insert some edges, then:
curl ".../edges/agg/__count__?start=1&direction=OUT"
# → { "groups": [{ "start": 1, "direction": "OUT", "value": <N>, "context": {} }], "count": 1, "context": {} }

# ranges must be omitted for __count__
curl ".../edges/agg/__count__?start=1&direction=OUT&ranges=foo%3Dbar"
# → 400 Bad Request

AI Assistance

  • This PR was written largely with AI assistance.
    • Tool / model: Claude Code (claude-sonnet-4-6)

…UNT query

- Add Constants.Group.COUNT_SENTINEL ("__count__") as a reserved group name
- QueryService.agg() detects the sentinel and delegates to the native
  edge-count path (TableBinding.count), mapping EdgeCountPayload ->
  EdgeAggPayload (count field -> value field)
- require(ranges == null) when group is __count__; ranges is not meaningful
  for a count query and would otherwise be silently ignored
- Make ranges nullable in QueryService.agg() and EdgeQueryController.agg();
  non-sentinel groups still require ranges (enforced via requireNotNull)
- Add E2E tests covering OUT/IN counts, multi-start, ranges-rejection,
  and missing-group validation

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
@eazyhozy eazyhozy self-assigned this Jun 30, 2026
@eazyhozy eazyhozy changed the title feat: support __count__ sentinel in AGG view to delegate to native COUNT query Support __count__ sentinel in AGG view to delegate to native COUNT query Jun 30, 2026
- Add start field assertion to OUT/IN count tests
- Compare agg __count__ value against native /edges/count as ground
  truth, instead of hardcoded expected values (embedded MockHTable
  does not increment counters via batch, so both paths return the same
  implementation-consistent value)
- Multi-start test now asserts per-node value for each start key
- Replace no_such_group regression with by_category (a real schema
  group), which correctly exercises the requireNotNull(ranges) path

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
@eazyhozy
eazyhozy marked this pull request as ready for review June 30, 2026 04:55
@eazyhozy
eazyhozy requested a review from em3s as a code owner June 30, 2026 04:55
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jun 30, 2026
@eazyhozy

eazyhozy commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

@em3s Could you take a look when you have a moment?

This PR adds __count__ as a sentinel group name in the AGG endpoint — when group == "__count__", the request is internally delegated to the native edge-count query instead of resolving a metadata-defined group. Part of the unified TopK work (#369).

@em3s

em3s commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LGTM.

Nit: consider rejecting group names that start with _ (or the sentinel itself) at schema creation time.

Nice work @eazyhozy !

@em3s
em3s merged commit cdde55c into main Jul 2, 2026
2 checks passed
@em3s
em3s deleted the feat/agg-count-sentinel branch July 2, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants