Skip to content

feat(clp-s): Support per-archive unique-value aggregation output to stdout and the results cache.#2367

Open
davemarco wants to merge 66 commits into
y-scope:mainfrom
davemarco:uniqueimpl
Open

feat(clp-s): Support per-archive unique-value aggregation output to stdout and the results cache.#2367
davemarco wants to merge 66 commits into
y-scope:mainfrom
davemarco:uniqueimpl

Conversation

@davemarco

@davemarco davemarco commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a --unique search aggregation, computing the distinct values of a field across matched records and writing them to stdout or the results cache. Continues the aggregation work from #2326, #2342, and #2345.

Outputs one document per distinct value, for both destinations:

{archive_id, field, value}

Changes

  • Adds --unique FIELD, supported by both the stdout and results-cache destinations.
  • New UniqueAggregation reads the field from each matched record and accumulates distinct scalar values in a std::set

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Tested a few queries on mongodb dataset

Summary by CodeRabbit

  • New Features

    • Added --unique search aggregation option to return distinct values for a specified field.
    • --unique supports integer, floating-point, string, and boolean values.
    • Updated search help and examples to document --unique.
  • Performance

    • Search results output now writes to the cache in configurable batches, improving handling of larger result sets.
  • Bug Fixes

    • Improved validation for --unique field names and field paths (including rejecting unescaped wildcards).
    • Search now safely ignores missing/invalid/unsupported field values.
    • Reducers now allow only count-based aggregations (count and count-by-time).

davemarco and others added 30 commits June 11, 2026 13:36
…e results cache.

Allows --count and --count-by-time to be used with the results-cache output handler, writing aggregation results directly to MongoDB via _id-keyed atomic $inc upserts so that partial results from multiple search processes merge correctly without a reducer.
…he search usage text outputs to the reducer.
…dout.

Adds `--count` and `--count-by-time` to the stdout output handler, emitting per-archive results as newline-delimited JSON. The options may be given without naming the `stdout` handler (e.g. `clp-s s <archives> <query> --count`), and the kv-ir search path now reports these aggregations as unsupported, consistent with the reducer and results-cache handlers.
… results cache.

Adds --min/--max <field> aggregations, extracting the field's numeric value from each matched record's marshalled JSON. Unifies the results-cache count handlers into a single AggregationToResultsCacheOutputHandler handling count, count-by-time, min, and max.
…ers.

- Take string_view for the results-cache handler uri/collection/dataset/archive_id
  params and materialize std::string only at the mongocxx call sites.
- Drop the redundant ::clp_s:: qualifier on the count handlers' base class.
- Rename the count-by-time write timestamp param to timestamp_ms to match the
  bucket size unit.
…n handler.

Merges the results-cache count work and applies the same review fixes to
AggregationToStdoutOutputHandler: take string_view for archive_id, drop the
redundant ::clp_s:: qualifier on the base class, rename the count-by-time
bucket size to count_by_time_bucket_size_ms, and rename the count-by-time
write timestamp param to timestamp_ms.
davemarco and others added 6 commits June 29, 2026 15:46
…e results cache.

Add a --unique FIELD aggregation that collects the distinct scalar values of a field across matched records, emitting one {field, value} result document per value through the existing aggregation sinks. Factor the shared field-path tokenization and JSON navigation out of MinMaxAggregation into reusable helpers, and rewrite the reducer output-handler restriction as a whitelist.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds --unique search aggregation for distinct scalar field values, refactors shared JSON field extraction, and updates results-cache output to batch writes with retained flush errors.

Changes

Unique aggregation and results-cache output

Layer / File(s) Summary
Aggregation model and value extraction
components/core/src/clp_s/aggregators.*
AggregationValue now supports booleans; shared field and JSON extraction handles scalar values; UniqueAggregator collects distinct values and MinMaxAggregator uses the shared logic.
CLI aggregation selection and validation
components/core/src/clp_s/CommandLineArguments.*
The search CLI accepts and validates --unique, constructs UniqueAggregator, documents the option, and rejects unsupported reducer aggregations.
Batched results-cache persistence
components/core/src/clp_s/AggregationSink.*, components/core/src/clp_s/clp-s.cpp, components/core/src/clp_s/archive_constants.hpp
ResultsCacheSink batches insert_many operations, retains flush errors, receives options.batch_size, and adds the cached search value key.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SearchCLI
  participant UniqueAggregator
  participant ResultsCacheSink
  participant ResultsCache
  SearchCLI->>UniqueAggregator: construct from --unique field
  SearchCLI->>UniqueAggregator: add_record for matched records
  UniqueAggregator-->>ResultsCacheSink: emit distinct aggregation results
  ResultsCacheSink->>ResultsCache: batch insert_many
  ResultsCache-->>ResultsCacheSink: flush result
Loading

Possibly related PRs

  • y-scope/clp#2229: Related aggregation-option parsing and reducer validation changes.
  • y-scope/clp#2326: Related results-cache batching and output-handler wiring.
  • y-scope/clp#2342: Related CLI aggregation dispatch and reducer support changes.

Suggested reviewers: davidlion, gibber9809

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding per-archive unique-value aggregation output to stdout and the results cache.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Add bool to AggregationValue so --unique treats booleans as distinct scalar values, and flush ResultsCacheSink in batches so high-cardinality aggregations don't buffer every document, surfacing mid-stream database errors.
@davemarco davemarco changed the title feat(clp-s): Support unique-value aggregation output to stdout and the results cache. feat(clp-s): Support unique and unique-count aggregation output to stdout and the results cache. Jul 6, 2026
@davemarco davemarco changed the title feat(clp-s): Support unique and unique-count aggregation output to stdout and the results cache. feat(clp-s): Support unique-value aggregation output to stdout and the results cache. Jul 6, 2026
davemarco and others added 8 commits July 6, 2026 12:47
- Rename the per-record aggregator classes and their variant from
  `*Aggregation`/`Aggregation` to `*Aggregator`/`Aggregator`, keeping
  "aggregation" for the operation's data/output (value, result, sink,
  output handler).
- Rename ambiguous `_ms` identifiers to `_millisecs`.
- Use `<clp_s/...>` includes, brace-init constexpr members, and tidy
  doc-comments (possessive wording, hoist implementation notes).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts:
#	components/core/src/clp_s/AggregationSink.cpp
#	components/core/src/clp_s/AggregationSink.hpp
#	components/core/src/clp_s/CommandLineArguments.cpp
#	components/core/src/clp_s/CommandLineArguments.hpp
#	components/core/src/clp_s/aggregators.cpp
#	components/core/src/clp_s/aggregators.hpp
#	components/core/src/clp_s/archive_constants.hpp
@davemarco davemarco marked this pull request as ready for review July 15, 2026 02:23
@davemarco davemarco requested review from a team and gibber9809 as code owners July 15, 2026 02:23
@davemarco davemarco requested a review from davidlion July 15, 2026 02:25

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/core/src/clp_s/aggregators.cpp`:
- Around line 168-195: Add or confirm unit coverage for UniqueAggregator,
including scalar conversion through to_aggregation_value (especially booleans),
field lookup through find_field_value, and deduplication of mixed-type values
across heterogeneous schemas. If tests are maintained elsewhere in the PR,
ensure they explicitly exercise these behaviors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6a8aaab0-89fd-4bcc-a944-c2ce5b6a104b

📥 Commits

Reviewing files that changed from the base of the PR and between 46f0c0a and 2d2f5c6.

📒 Files selected for processing (8)
  • components/core/src/clp_s/AggregationSink.cpp
  • components/core/src/clp_s/AggregationSink.hpp
  • components/core/src/clp_s/CommandLineArguments.cpp
  • components/core/src/clp_s/CommandLineArguments.hpp
  • components/core/src/clp_s/aggregators.cpp
  • components/core/src/clp_s/aggregators.hpp
  • components/core/src/clp_s/archive_constants.hpp
  • components/core/src/clp_s/clp-s.cpp

Comment thread components/core/src/clp_s/aggregators.cpp
@davemarco davemarco changed the title feat(clp-s): Support unique-value aggregation output to stdout and the results cache. feat(clp-s): Support per-archive unique-value aggregation output to stdout and the results cache. Jul 15, 2026
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.

2 participants