Skip to content

ESQL: SUM long overflow fix and TransportVersionAware interface#141272

Merged
ncordon merged 56 commits intoelastic:mainfrom
ivancea:esql-sum-agg-overflow-warning
Mar 31, 2026
Merged

ESQL: SUM long overflow fix and TransportVersionAware interface#141272
ncordon merged 56 commits intoelastic:mainfrom
ivancea:esql-sum-agg-overflow-warning

Conversation

@ivancea
Copy link
Copy Markdown
Contributor

@ivancea ivancea commented Jan 26, 2026

Fixes #110437

Recovers an old PR now that we have minTransportVersion available: #116170

SUM(long) throws on an overflow, leading to a 500 error and fully breaking the query.
This PR introduces a warnExceptions in the evaluator (Introduced here and never used yet: #111829) to instead show a warning and return a null for that group/aggregation.

Because this is an aggregation intermediate state change, this isn't BWC. So a new TransportVersionAware interface was introduced to let the function modify its behavior based on the minTransportVersion across all the query clusters (This is the new bit that we didn't have in the original PR).

@ivancea ivancea added >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v9.4.0 labels Jan 26, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @ivancea, I've created a changelog YAML for you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added tests for a combination of:

  • FROM and ROW
  • Grouping and not grouping
  • SUM and AVG (Surrogates to SUM)

};
case SUM -> switch (dataType) {
case LONGS -> new SumLongAggregatorFunctionSupplier();
case LONGS -> new SumLongAggregatorFunctionSupplier(-1, -2, "");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FYI because agg-generated code is in the compute project, it can't receive Source (esql/core) like evaluators do. So we pass the line, column and text directly.
This was made in the warnExceptions PR

@ivancea ivancea requested a review from alex-spies January 28, 2026 12:47
Copy link
Copy Markdown
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

This is currently blocked on the outcome of #138805.

That said, I like this approach. Looks nice and simple, and everything is clear after the substitutions step in the optimizer.

readWindow(in),
readSummationMode(in)
readSummationMode(in),
in.getTransportVersion().supports(ESQL_SUM_LONG_OVERFLOW_FIX) ? in.readBoolean() : true
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.

++

* Returns the expression to be replaced by or {@code null} if this cannot
* be replaced.
*/
Expression forTransportVersion(TransportVersion minTransportVersion);
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.

++,lgtm

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.

I think we need some more explanation here?
I think there are 3 cases.

  • Replaced successfully
  • Doesn't need replace (returned same as before)
  • Cannot be replaced (but maybe it should and if unsuccessful it should throw about unsupported feature)?

It seems right now we don't have the error code/throwing in the API design, but we might need it. We should think about this when designing the new interface and provide comments here about the expected behavior in that case. I think we can just throw in the forTransportVersion implementation, maybe just improve the comment

new ReplaceAliasingEvalWithProject(),
new SkipQueryOnEmptyMappings(),
new SubstituteSurrogateExpressions(),
new SubstituteTransportVersionAwareExpressions(),
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.

++

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.

This is brittle. If there is a rule after this one that introduces sum and it will create a non-bwc sum and fail on old nodes (where before it would succeed unless there is an overflow). I reviewed the rules after, they seem OK right now (but @alex-spies you might know more details). But rules change from time to time.

Maybe it is safer to start with the old compatible sum version, and use this rule to make it new version of the sum?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add to toString to see it in the plan outputs?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 72 out of 78 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 73 out of 79 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 79c754fd-3bc2-48d9-a191-08285bfaacca

📥 Commits

Reviewing files that changed from the base of the PR and between 53355a6 and 9ea71bc.

⛔ Files ignored due to path filters (8)
  • server/src/main/resources/transport/definitions/referable/esql_sum_long_overflow_fix.csv is excluded by !**/*.csv
  • server/src/main/resources/transport/upper_bounds/9.4.csv is excluded by !**/*.csv
  • x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongAggregatorFunction.java is excluded by !**/generated/**
  • x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongAggregatorFunctionSupplier.java is excluded by !**/generated/**
  • x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongGroupingAggregatorFunction.java is excluded by !**/generated/**
  • x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumOverflowingLongAggregatorFunction.java is excluded by !**/generated/**
  • x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumOverflowingLongAggregatorFunctionSupplier.java is excluded by !**/generated/**
  • x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumOverflowingLongGroupingAggregatorFunction.java is excluded by !**/generated/**
📒 Files selected for processing (104)
  • benchmarks/src/main/java/org/elasticsearch/benchmark/compute/operator/AggregatorBenchmark.java
  • docs/changelog/141272.yaml
  • test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java
  • x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/SumLongAggregator.java
  • x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/SumOverflowingLongAggregator.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/CountDistinctIntAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/CountDistinctLongAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/SumDenseVectorAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/SumDenseVectorGroupingAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/SumIntAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/SumLongAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/SumLongGroupingAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/SumOverflowingLongAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/SumOverflowingLongGroupingAggregatorFunctionTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/blockhash/CategorizeBlockHashTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BlockSerializationTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/AggregationOperatorTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/ChangePointOperatorTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/HashAggregationOperatorTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/WarningsTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/fuse/LinearScoreEvalOperatorTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/fuse/RrfScoreEvalOperatorTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/lookup/EnrichQuerySourceOperatorTests.java
  • x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/lookup/LookupQueryOperatorTests.java
  • x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearch/compute/test/TestWarningsSource.java
  • x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeApproximationRestTest.java
  • x-pack/plugin/esql/qa/testFixtures/src/main/resources/k8s-timeseries-sum-over-time.csv-spec
  • x-pack/plugin/esql/qa/testFixtures/src/main/resources/stats.csv-spec
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/capabilities/TransportVersionAware.java
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Sum.java
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/SubstituteTransportVersionAwareExpressions.java
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/Versioned.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/evaluator/command/UriPartsFunctionBridgeTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractAggregationTestCase.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/AvgTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SumOverTimeTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SumSerializationTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SumTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/WeightedAvgTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/SubstituteTransportVersionAwareGoldenTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/SubstituteTransportVersionAwareExpressionsTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/SubstituteRoundToGoldenTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/plugin/LateMaterializationPlannerGoldenTests.java
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/querydsl/query/SingleValueMatchQueryTests.java
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testFuse/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testFuseLinear/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testFuseWithEval/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testInlineStatsAggAndGroup/load/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testInlineStatsAggAndGroup/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testInlineStatsMixed/load/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testInlineStatsMixed/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsAggAndAliasedGroup/load/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsAggAndAliasedGroup/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsAggAndAliasedGroupWithExpression/load/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsAggAndAliasedGroupWithExpression/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsAggAndGroup/load/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsAggAndGroup/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsMixed/load/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsMixed/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testStatsMixedAndExpressions/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testTBucketAggregateUnmapped/load/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/analysis/golden_tests/AnalyzerUnmappedGoldenTests/testTBucketAggregateUnmapped/nullify/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/local_physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/local_reduce_physical_optimization_data_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/local_reduce_physical_optimization_reduce_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/local_reduce_planned_data_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/local_reduce_planned_reduce_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/logical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLong/query.esql
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/local_physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/local_reduce_physical_optimization_data_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/local_reduce_physical_optimization_reduce_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/local_reduce_planned_data_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/local_reduce_planned_reduce_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/logical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumGetsReplacedWithSafeLongAndMultipleAggsAndGroups/query.esql
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/local_physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/local_reduce_physical_optimization_data_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/local_reduce_physical_optimization_reduce_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/local_reduce_planned_data_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/local_reduce_planned_reduce_driver.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/logical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/golden_tests/SubstituteTransportVersionAwareGoldenTests/testSumStaysWithOverflowingLong/query.esql
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/ForkGoldenTests/testHybridSearch/analysis.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/ForkGoldenTests/testHybridSearch/local_physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/ForkGoldenTests/testHybridSearch/logical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/ForkGoldenTests/testHybridSearch/physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/SubstituteRoundToGoldenTests/testDateTruncBucketTransformToQueryAndTagsWithMultipleAggregates/bucket/local_physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/SubstituteRoundToGoldenTests/testDateTruncBucketTransformToQueryAndTagsWithMultipleAggregates/bucket/query.esql
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/SubstituteRoundToGoldenTests/testDateTruncBucketTransformToQueryAndTagsWithMultipleAggregates/date_trunc/local_physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/SubstituteRoundToGoldenTests/testDateTruncBucketTransformToQueryAndTagsWithMultipleAggregates/date_trunc/query.esql
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/SubstituteRoundToGoldenTests/testDateTruncBucketTransformToQueryAndTagsWithMultipleAggregates/round_to/local_physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/golden_tests/SubstituteRoundToGoldenTests/testDateTruncBucketTransformToQueryAndTagsWithMultipleAggregates/round_to/query.esql
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/plugin/golden_tests/LateMaterializationPlannerGoldenTests/testTopNThenStats/physical_optimization.expected
  • x-pack/plugin/esql/src/test/resources/org/elasticsearch/xpack/esql/plugin/golden_tests/LateMaterializationPlannerGoldenTests/testTopNThenStats/query.esql

📝 Walkthrough

Walkthrough

This pull request addresses long overflow handling in ESQL SUM aggregation (issue #110437). Previously, summing long values that overflow would crash with a 500 error. The fix introduces version-aware overflow handling: on supported transport versions, overflow returns null with a warning; on older versions, the original overflow-throwing behavior is preserved. Key changes include: a new SumOverflowingLongAggregator using Math.addExact to enforce overflow detection; updates to SumLongAggregator with a failed intermediate state to track warnings; a new TransportVersionAware interface enabling per-expression version-dependent substitutions; and updates to the Sum expression to select the appropriate aggregator supplier based on transport version and overflow mode. The optimizer pipeline now includes SubstituteTransportVersionAwareExpressions to rewrite Sum expressions at plan time when version support allows the safer behavior.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

@ncordon ncordon merged commit 9c376e5 into elastic:main Mar 31, 2026
35 checks passed
ncordon pushed a commit to ncordon/elasticsearch that referenced this pull request Apr 1, 2026
@ivancea ivancea deleted the esql-sum-agg-overflow-warning branch April 6, 2026 09:35
not-napoleon added a commit that referenced this pull request Apr 6, 2026
resolves #145381

I think this is a sequencing conflict with #141272, which applied a similar change to many other golden tests.
mromaios pushed a commit to mromaios/elasticsearch that referenced this pull request Apr 9, 2026
mromaios pushed a commit to mromaios/elasticsearch that referenced this pull request Apr 9, 2026
resolves elastic#145381

I think this is a sequencing conflict with elastic#141272, which applied a similar change to many other golden tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ESQL] Sum aggregation returns a 500 status code for overflow

6 participants