Add stats, extended_stats, and value_count support to DSL Calcite plugin - #22561
Add stats, extended_stats, and value_count support to DSL Calcite plugin#22561sachin-27 wants to merge 5 commits into
Conversation
Convert flat per-granularity execution results into the client's nested aggregation response using the original request as template. Co-authored-by: Varun <varunsm@amazon.com> Signed-off-by: Sachin Sriramagiri <srirasac@amazon.com>
Exclude SQL NULL groups from terms buckets (legacy parity), resolve granularity keys from the aggregate's input row type, use NUL key separator, null-safe toDouble error message. Signed-off-by: Sachin Sriramagiri <srirasac@amazon.com>
Co-authored-by: Varun <varunsm@amazon.com> Signed-off-by: Sachin Sriramagiri <srirasac@amazon.com>
PR Reviewer Guide 🔍(Review updated until commit b7abe1f)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to b7abe1f Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 2233e09
Suggestions up to commit 88231ca
|
|
❌ Gradle check result for 88231ca: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
| return new InternalAvg(agg.getName(), 0.0, 0, DocValueFormat.RAW, null); | ||
| } | ||
| return new InternalAvg(name, toDouble(value), 1, DocValueFormat.RAW, null); | ||
| return new InternalAvg(agg.getName(), toDouble(value), 1, DocValueFormat.RAW, null); |
There was a problem hiding this comment.
This encoding works only when the response is never reduced across shards or with another InternalAvg.
InternalAvg.reduce sums the sums variable of IntervalAvg and sums the counts variable of IntervalAvg and divides.
two shards each reporting (v, 1) reduce to (v1+v2)/2
There was a problem hiding this comment.
You're right on the encoding, but reduce doesn't run on this path. The engine aggregates across all shards and returns one single value. Verified this on a 3 node cluster setup on local
| .filter(r -> r.getType() == QueryPlans.Type.AGGREGATION) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| if (aggResults.isEmpty() || request.source() == null || request.source().aggregations() == null) { |
There was a problem hiding this comment.
can we compare this behaviour with vanilla?
When the request has aggregations but the plan produced no rows (empty index, filter matches nothing, etc.), this returns null, so the response omits the aggregations block entirely
whereas i think in vanilla it return the aggregations block with each sub-agg populated with empty/sentinel values (e.g. avg: {"value": null}, sum: {"value": 0.0})
There was a problem hiding this comment.
So aggResults.isEmpty() tests for empty aggregation plan result. So if request has aggregations, this will never evaluate to true so we will get output in format you are suggesting. Tested this out comparing with Vanilla for a seach matching both docs and both are in sync.
| agg.size(), | ||
| agg.shardSize() | ||
| ); | ||
| return new StringTerms( |
There was a problem hiding this comment.
For a numeric field like user_id for example
{
"aggs": {
"by_user": {
"terms": { "field": "user_id" }
}
}
}
Where user_id: integer in the mapping.
it will returns StringTerms with string keys.
{ "key": "42", "doc_count": 340 } which will be incorrect right?
shouldn't we detect value source type from mapping and that accordingly generate
Support the missing and format parameters on metric aggregations via literal-derived input columns, reject non-numeric fields with the classic error shape, and type terms bucket keys like the classic path. Signed-off-by: Sachin Sriramagiri <srirasac@amazon.com>
|
Persistent review updated to latest commit 2233e09 |
Distinguish the allocator interface handed to translators from the List of LiteralColumn carried in AggregationMetadata; the plural type name read as a collection. Rename the builder factory method to match. Signed-off-by: Sachin Sriramagiri <srirasac@amazon.com>
|
Persistent review updated to latest commit b7abe1f |
|
❌ Gradle check result for b7abe1f: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Description
Adds support for stats, extended_stats, and value_count metric aggregations to the DSL Calcite plugin.
Stacks on #22526 — only the last commit is new to this PR
Key changes:
• Refactored MetricTranslator interface to support multi-metric aggregations (returns List instead of single call)
• Implemented StatsMetricTranslator (count, min, max, sum)
• Implemented ExtendedStatsMetricTranslator (count, min, max, sum, variance)
• Implemented ValueCountMetricTranslator (count on specific field)
• Made COUNT type explicitly non-nullable to match SQL semantics
Note:
Derived metrics like avg and std_deviation are computed by InternalStats/InternalExtendedStats from the base metrics rather than in SQL.
Tests:
Added unit tests for all three new translators covering valid values, null handling, and error cases.