Skip to content

feat(clp-s): Support per-archive group-by count aggregation output to stdout and the results cache.#2379

Draft
davemarco wants to merge 68 commits into
y-scope:mainfrom
davemarco:group-by-count
Draft

feat(clp-s): Support per-archive group-by count aggregation output to stdout and the results cache.#2379
davemarco wants to merge 68 commits into
y-scope:mainfrom
davemarco:group-by-count

Conversation

@davemarco

Copy link
Copy Markdown
Contributor

Description

Adds a --count-by search aggregation, grouping matched records by the value of a
field and counting each group, writing the results to stdout or the results cache. Continues
the aggregation work from #2326, #2342, #2345, and #2367.

Outputs one document per distinct value, for both destinations:

{archive_id, field, value, count}

Changes

  • Adds --count-by FIELD, supported by both the stdout and results-cache destinations.
  • New GroupByCountAggregator reads the field from each matched record and accumulates
    per-value counts in a std::map.

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

TBU

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 22 commits June 28, 2026 15:05
Also wrap an IntFloatCompare comment and drop a stray blank line.
…reducer dispatch, rename aggregation error.

- CountByTimeAggregation rejects non-positive bucket sizes.
- ResultsCacheSink clears its buffer after a successful flush to avoid duplicate inserts.
- Reducer output dispatch handles count-by-time explicitly and throws on unsupported aggregations.
- Rename KvIrSearchErrorEnum::CountSupportNotImplemented to AggregationSupportNotImplemented.
…er clang-tidy.

Make connect_to_results_cache a non-template function defined in
ResultsCacheUtils.cpp instead of a header-only template. The template existed
only to throw each caller's nested OperationFailed, but the call sites are caught
as std::exception and TraceableException::what() ignores the exception type, so
collapsing them into a single ResultsCacheConnectionError is behavior-preserving.

This also gives the header a sibling .cpp, so clang-tidy resolves the mongocxx
include path (header-only templates fall back to a non-mongo compile command and
fail with "mongocxx/client.hpp file not found"). Removes the now-dead nested
OperationFailed classes and the reducer parse-time comment.
…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.
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.
- 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>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: af6ff8b3-acd9-413e-abb5-7e2fa0b6669e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ 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.

# 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 changed the title feat(clp-s): Support group-by count aggregation output to stdout and the results cache. feat(clp-s): Support per-archive group-by count aggregation output to stdout and the results cache. Jul 15, 2026
# Conflicts:
#	components/core/src/clp_s/aggregators.cpp
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