Skip to content

Adding a Jitexpr ValueSource to allow jitexpr in aggregations. - #3162

Merged
fulmicoton merged 3 commits into
mainfrom
paul.masurel/jitexpr-value-source
Oct 13, 2026
Merged

fulmicoton merged 3 commits into
mainfrom
paul.masurel/jitexpr-value-source

Conversation

@fulmicoton

@fulmicoton fulmicoton commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Adds JitExprValueSourceProvider, a ValueSourceProvider that computes the values of a calculated field with a jitexpr expression over the fast fields of a segment. Registered in a ValueSourceRegistry, a calculated field can be used by aggregations like a fast field.

Builds on the ValueSource framework (#3160, #3171).

Semantics

  • Types are resolved per segment, from the column types of the segment and the types the aggregation accepts. E.g. (ADD a 1i64) is i64 on a segment where a is i64, and f64 where it is f64.
    • An expression that can never produce an accepted type fails the aggregation (e.g. jitexpr has no date type).
    • An expression that does not produce an accepted type on a given segment has no value on that segment.
  • Values: each input takes the first value of the doc. A null result means the doc has no value, so a doc has at most one value.
  • Text results are interned in a DynamicTermDictionary owned by the source. Their term ords are in first-seen order, not sorted with the terms.
  • Compilation goes through the index expression compilation cache: segments with the same column types share the compiled function.
  • A calculated field shadows a fast field with the same name, including on segments where it has no value.

Terms aggregation restrictions

On computed sources:

  • min_doc_count: 0 is rejected: we cannot list all the values a computed source could take.
  • Ordering by _key is rejected for text sources only (their ords are not sorted with the terms). Numeric and bool values use the monotonic u64 mapping, so _key ordering works.
  • include / exclude and missing already required a physical text column.

ValueSourceDictionary::ords_sorted_with_terms is removed: the rule above replaces it.

Implementation

  • InputColumn: a fast-field column bound to an input of the compiled function.
  • TermResolver (term_resolver.rs): resolves the term ords of text inputs. Dictionaries with at most 1024 terms are decoded upfront. Larger ones are decoded on demand, with a bounded cache.
  • JitExprValueSource::load_block evaluates a block. eval_single_doc evaluates one doc without the block buffers.
  • JitExprValueSourceProvider::open_segment returns the concrete source (AlwaysNull / Constant / Variable). for_segment wraps it.
  • StrColumn::into_parts (columnar) splits a text column into its dictionary and its term ord column.

JitExprPredicate refactor

JitExprPredicate now builds its segment state with JitExprValueSourceProvider::open_segment and evaluates docs with eval_single_doc. This removes the duplicated binding / compilation code. Text inputs now go through TermResolver instead of decoding the term of every doc. The necessary presence condition is built from the column indexes of the compiled inputs.

Cargo

  • New optional dependency hashbrown, enabled by the jitexpr feature (term interning).
  • jitexpr is added to the default features.

Tests

  • Aggregations over calculated fields: metrics, histogram, range, terms (text and numeric), cardinality, multivalued inputs, per-segment result types, compilation cache, comparison with materialized fields.
  • Rejection of the unsupported terms options.
  • TermResolver: full decode, cached decode, eviction, single-ord path.
  • eval_single_doc matches load_block.
  • Text predicate on a dictionary larger than the full-decode threshold.

@fulmicoton fulmicoton closed this Oct 9, 2026
@fulmicoton fulmicoton reopened this Oct 9, 2026
@fulmicoton-dd
fulmicoton-dd force-pushed the paul.masurel/jitexpr-value-source branch 2 times, most recently from 8c855c4 to 1555344 Compare October 9, 2026 12:58
@fulmicoton-dd
fulmicoton-dd force-pushed the paul.masurel/aggregations-value-source-framework branch from 021070f to 13782b2 Compare October 9, 2026 15:56
Base automatically changed from paul.masurel/aggregations-value-source-framework to main October 9, 2026 16:07
@fulmicoton-dd
fulmicoton-dd force-pushed the paul.masurel/jitexpr-value-source branch 6 times, most recently from f312825 to ac9675e Compare October 12, 2026 08:52
@fulmicoton-dd
fulmicoton-dd force-pushed the paul.masurel/jitexpr-value-source branch 2 times, most recently from 7554754 to d5630fd Compare October 12, 2026 09:52
@fulmicoton
fulmicoton marked this pull request as ready for review October 12, 2026 09:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T16:43:05.018737Z c5e5e15 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@fulmicoton fulmicoton changed the title First stab Adding a Jitexpr ValueSource to allow jitexpr in aggregations. Oct 12, 2026
@fulmicoton
fulmicoton requested a review from Mallets October 12, 2026 09:54
@fulmicoton-dd
fulmicoton-dd force-pushed the paul.masurel/jitexpr-value-source branch from d5630fd to 29f83cc Compare October 12, 2026 09:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5630fdc38

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread Cargo.toml
Comment on lines +189 to +191
[[example]]
name = "aggregation_jitexpr"
required-features = ["jitexpr"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the declared example source file

The new [[example]] target has neither examples/aggregation_jitexpr.rs nor examples/aggregation_jitexpr/main.rs anywhere in the repository. Cargo therefore rejects the manifest before resolving or compiling any target (can't find aggregation_jitexpr example), so all Cargo build, test, and metadata commands fail even when the jitexpr feature is not enabled.

Useful? React with 👍 / 👎.

Comment thread src/aggregation/value_source/jitexpr_value_source/mod.rs Outdated
Comment thread src/aggregation/value_source/jitexpr_value_source/term_resolver.rs
Comment thread src/aggregation/value_source/jitexpr_value_source/term_resolver.rs
Comment thread src/aggregation/value_source/jitexpr_value_source/term_resolver.rs
Comment thread src/aggregation/value_source/jitexpr_value_source/term_resolver.rs
Comment thread src/aggregation/value_source/jitexpr_value_source/mod.rs
Comment thread src/aggregation/value_source/jitexpr_value_source/mod.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5e5e15de7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +278 to +280
VarType::Str => result
.as_str()
.map(|term: &str| term_dictionary.intern(term.as_bytes())),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Account computed string terms against the aggregation limit

When a string expression produces many distinct values, every result is retained in DynamicTermDictionary, but these allocations are never reported to AggregationLimitsGuard. This can bypass even a small configured memory limit—for example, a count aggregation over (UPPER unique_id) interns every transformed ID while the count collector itself uses constant memory—and may exhaust the process instead of returning MemoryExceeded. Track dictionary buffer, offsets, and hash-table growth against the request's aggregation guard, or avoid interning where the collector does not need term identities.

Useful? React with 👍 / 👎.

Comment thread src/aggregation/value_source/jitexpr_value_source/term_resolver.rs
@fulmicoton
fulmicoton merged commit 9f9030a into main Oct 13, 2026
8 checks passed
@fulmicoton
fulmicoton deleted the paul.masurel/jitexpr-value-source branch October 13, 2026 08:59
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.

3 participants