You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "david-mollitor-db (via GitHub)" <gi...@apache.org> on 2026/09/22 18:27:46 UTC

[PR] [WIP][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal [spark]

david-mollitor-db opened a new pull request, #58972:
URL: https://github.com/apache/spark/pull/58972

   ### What changes were proposed in this pull request?
   
   Declare `CheckOverflow` null-intolerant, matching its sibling `MakeDecimal`:
   
   ```scala
   override def nullIntolerant: Boolean = true
   ```
   
   `CheckOverflow` extends `UnaryExpression` and overrides `nullSafeEval`, so `UnaryExpression.eval` returns `null` whenever the child is `null` -- i.e. it already satisfies the null-intolerance contract ("any null input results in null output"). The property was simply never declared: when the `NullIntolerant` marker trait was replaced by a `def` (SPARK-50241), the adjacent `UnscaledValue` and `MakeDecimal` were updated but `CheckOverflow` was missed.
   
   `Cast` -- which shares the same "throws under ANSI overflow / returns null otherwise" shape -- already declares `nullIntolerant = true`, as do `MakeDecimal`, `UnscaledValue`, and the arithmetic expressions. This aligns `CheckOverflow` with them.
   
   ### Why are the changes needed?
   
   `nullIntolerant` is consumed by the optimizer to:
   - fold a null-literal input to a null literal (`NullPropagation`), and
   - infer `IsNotNull(child)` constraints and push down `IsNotNull` filters (`QueryPlanConstraints.scanNullIntolerantAttribute` / `InferFiltersFromConstraints`).
   
   `CheckOverflow` wraps decimal results throughout the plan (e.g. the decimal serializers in `SerializerBuildHelper`), so declaring the property it already honors lets these optimizations see through it, consistent with `MakeDecimal`. This is a follow-up to the nullability alignment in SPARK-59643 (#58913), addressing a related consistency gap raised in that review.
   
   The direction the optimizer relies on holds even though `CheckOverflow` with `nullOnOverflow = true` can also return `null` from a non-null input on overflow: the contract only requires "null in => null out", not the converse -- the same situation as `Cast`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. This only declares an optimizer-visible property that `CheckOverflow` already honored at runtime; computed values and error behavior are unchanged. It can enable additional `IsNotNull` filter inference / null folding in query plans, but those are semantics-preserving: an inferred `IsNotNull` only removes rows whose `CheckOverflow` result would already be null, and null folding only fires for null-literal inputs, which never overflow or throw.
   
   ### How was this patch tested?
   
   Existing suites pass unchanged, with no plan or golden-file churn:
   - catalyst: `DecimalAggregatesSuite`, `DecimalExpressionSuite`, `InferFiltersFromConstraintsSuite`
   - sql/core: `PlannerSuite`, `AlignUpdateAssignmentsSuite`, `AlignMergeAssignmentsSuite`
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Isaac
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-59719][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal [spark]

Posted by "david-mollitor-db (via GitHub)" <gi...@apache.org>.
david-mollitor-db commented on PR #58972:
URL: https://github.com/apache/spark/pull/58972#issuecomment-5798354970

   Thanks, @dongjoon-hyun -- both addressed:
   
   1. **Description / commit message.** You're right, corrected both. `CheckOverflow` never mixed in the `NullIntolerant` trait (checked `a84ca5e46e6^`: there `UnscaledValue` and `MakeDecimal` had the trait, `CheckOverflow` did not), so it was never declared null-intolerant -- a pre-existing gap, independent of SPARK-50241.
   
   2. **Tests.** Added both of your examples:
      - `InferFiltersFromConstraintsSuite`: `IsNotNull('d)` is inferred from `CheckOverflow('d, ...) > 0`.
      - a new `NullPropagationSuite`: `CheckOverflow(Literal(null, ...), ...)` folds to a null literal under a NullPropagation-only batch, so the fold is attributable to the new null-intolerance rather than plain constant folding.
   
   Force-pushed. Thanks again for the careful review!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-59719][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal [spark]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #58972:
URL: https://github.com/apache/spark/pull/58972#issuecomment-5799102949

   Thank you for addressing the comments, @david-mollitor-db. The new tests look good to me; both fail without the `nullIntolerant` change, so they cover the new behavior.
   
   One remaining item: the PR description is missing the `### Was this patch authored or co-authored using generative AI tooling?` section from the PR template. Since the commit has `Co-authored-by: Isaac`, could you add that section with the `Generated-by: ...` line if applicable?
   
   Minor nit (non-blocking): because `CheckOverflow` is foldable when its child is foldable, `ConstantFolding` already folds `CheckOverflow(null literal)` in the real optimizer. The practical benefit here is mainly the `IsNotNull` inference and the `FilterExec` output nullability.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-59719][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal [spark]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun closed pull request #58972: [SPARK-59719][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal
URL: https://github.com/apache/spark/pull/58972


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-59719][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal [spark]

Posted by "david-mollitor-db (via GitHub)" <gi...@apache.org>.
david-mollitor-db commented on PR #58972:
URL: https://github.com/apache/spark/pull/58972#issuecomment-5799761963

   > One remaining item: the PR description is missing the ### Was this patch authored or co-authored using generative AI tooling? section from the PR template. Since the commit has Co-authored-by: Isaac, could you add that section with the Generated-by: ... line if applicable?
   
   :joy:
   
   Sorry, I manually removed - I thought somewhere else you mentioned you wanted to remove that. Will restore.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-59719][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal [spark]

Posted by "david-mollitor-db (via GitHub)" <gi...@apache.org>.
david-mollitor-db commented on PR #58972:
URL: https://github.com/apache/spark/pull/58972#issuecomment-5795318611

   @dongjoon-hyun As requested :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-59719][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal [spark]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #58972:
URL: https://github.com/apache/spark/pull/58972#issuecomment-5801584208

   **Merge Summary:**
   - merged into master https://github.com/apache/spark/commit/9929c6f0387ab11538c94880b5ece7aee17aeec1
   - merged into branch-4.x https://github.com/apache/spark/commit/6faab23ad4ac084eedba82188a66b1fe016c78fc
   
   *Posted by `merge_spark_pr.py`*


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-59719][SQL] Mark CheckOverflow as null-intolerant to match MakeDecimal [spark]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #58972:
URL: https://github.com/apache/spark/pull/58972#issuecomment-5797569351

   Thank you for making a PR, @david-mollitor-db. The change itself looks correct to me: `CheckOverflow` uses `nullSafeEval`/`nullSafeCodeGen`, so null-in => null-out holds in both interpreted and codegen paths. I also checked the consumers of `nullIntolerant` (`NullPropagation`, `QueryPlanConstraints.scanNullIntolerantAttribute`, `FilterExec.notNullPreds`), and `NullDownPropagation` is protected by the `supportedNullIntolerant` allowlist, so `IsNull(CheckOverflow(x))` will not be rewritten into `IsNull(x)`.
   
   A few comments:
   
   1. The PR description and the commit message say that `CheckOverflow` was missed when SPARK-50241 replaced the `NullIntolerant` mixin with a `def`. That's not accurate. Before SPARK-50241 (a84ca5e46e6), `CheckOverflow` was `UnaryExpression with SupportQueryContext` and never mixed in `NullIntolerant`. So it was never declared, not missed during SPARK-50241. Could you fix the description?
   
   2. Could you add a test case for the new behavior? Existing suites passing only shows that nothing changed. For example:
      - `InferFiltersFromConstraintsSuite`: `IsNotNull('a)` is inferred from a filter like `CheckOverflow('a, ...) > 0`.
      - `NullPropagation`: `CheckOverflow(Literal(null, DecimalType(...)), ...)` is folded to a null literal.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org