ANSI integral SUM overflow reports "integer overflow" without Spark's try_add suggestion
Maintainers usually reply within 1 day
@0lai0 is already working on this.
Since Oct 6, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start with native/spark-expr/src/agg_funcs/sum_int.rs and the three overflow sites described in the issue, then read the existing ANSI support - SUM function test in CometAggregateSuite. Compare Comet's error parameters with Spark's for both update and merge overflow paths. Done means the message and alternative parameters match Spark and the test verifies that comparison.
Written by the indexing model from the issue text.
Description
Describe the bug
Under spark.sql.ansi.enabled=true, an integral SUM overflow in Comet raises ARITHMETIC_OVERFLOW with the message parameter integer overflow and an empty alternative. Spark raises long overflow with the suggestion Use 'try_add' to tolerate overflow and return NULL instead.
Spark's SUM over integral input always returns LONG, and Sum adds through Add(left, right, evalContext) in both its update and merge expressions. So the overflow goes through MathUtils.addExact(Long, Long, context) with the try_add hint, the same on 3.4.3 through 4.2.0. Comet's native/spark-expr/src/agg_funcs/sum_int.rs raises arithmetic_overflow_error("integer") at its three overflow sites: the ungrouped update (which the ungrouped merge reuses), the grouped update, and the grouped merge.
Comet's decision to throw matches Spark. Only the message parameters differ, which matters to code that inspects getMessageParameters() or the message text.
This was part of item 2 in #5071, which also named SumInteger. #6217 assumed the rest of #5071 had been fixed, and #6249 fixes the binary +, - and * kernels but not SUM. Once #6249 removes the #6217 bullet, the compatibility guide no longer lists this divergence.
Steps to reproduce
SET spark.sql.ansi.enabled=true;
CREATE TABLE t (l BIGINT) USING parquet;
INSERT INTO t SELECT CASE WHEN id = 0 THEN 9223372036854775807 ELSE 1 END FROM range(0, 3, 1, 1);
SELECT SUM(l) FROM t;
-- Spark: [ARITHMETIC_OVERFLOW] long overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
-- Comet: [ARITHMETIC_OVERFLOW] integer overflow. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
The final merge diverges the same way when each of two partitions holds part of the overflowing sum.
Expected behavior
The message parameter is long overflow and alternative carries the try_add suggestion, as in Spark.
Additional context
Reproduced locally on Spark 3.4 and 4.1 for both the partial and the merge path. With the function_name field that #6249 adds to SparkError::ArithmeticOverflow, raising ArithmeticOverflow { from_type: "long", function_name: "try_add" } at the three call sites made Comet match Spark's error class, parameters and message on both paths.
The existing ANSI support - SUM function test in CometAggregateSuite only checks that both messages contain ARITHMETIC_OVERFLOW, so it passes either way. It should compare the message parameters with Spark's.
- Dominant language
- Scala
- Stars
- 1.3k
- Forks
- 383
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 413
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/datafusion-comet
-
Iceberg data tables whose names end with a metadata-table name fall back to SparkPossibly taken @aryan9948 claimed this 2 days ago. Openrequires-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/datafusion-comet#6719 · 1 comment ·
Maintainers usually reply within 1 day
-
Native from_json with a schema that repeats a field name fails with "ArrowArray struct has 2 children (expected 1)"Possibly taken @Samearth17 claimed this 3 days ago. Openarea:expressions area:ffi bug good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
apache/datafusion-comet#6592 ·
Maintainers usually reply within 1 day
-
Casting to a struct type with repeated field names fails with "ArrowArray struct has 2 children (expected 1)"Possibly taken @Samearth17 claimed this 3 days ago. Openarea:expressions area:ffi bug good first issue priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/datafusion-comet#6591 ·
Maintainers usually reply within 1 day
-
arrays_zip with two same-named inputs fails with "ArrowArray struct has 2 children (expected 1)"Possibly taken @mohitgurav20 claimed this 10 days ago. Openarea:expressions area:ffi bug priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/datafusion-comet#6251 · 4 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
ci: a transient Maven Central failure in lint-java is reported as a scalafix violationPossibly taken @andygrove claimed this 18 days ago. Openarea:ci bug priority:low
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion-comet#6060 ·
Maintainers usually reply within 1 day
All issues in apache/datafusion-comet
Similar issues
-
C21 publishes `reactivemongo/core/SSL` as Java 23 bytecode — TLS connections fail on any JDK < 23Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
ReactiveMongo/ReactiveMongo#1520 ·
Maintainers usually reply within 1 day
-
module: unknown type: bug/reported
Difficulty 1/5 Under an hour Newbie friendliness 78/100
OpenXiangShan/XiangShan#6688 ·
Maintainers usually reply within 1 day
-
bug documentation
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
bug 🐞 Untriaged user issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
valkey-io/valkey-glide#7306 · 1 comment ·
Maintainers usually reply within 2 days
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
lichess-org/lila#21988 · 1 comment ·
Maintainers usually reply within 1 day