Skip to content

[BugFix] Never raise a strict cast overflow error from a null row's data (backport #74903)#74958

Merged
wanpengfei-git merged 4 commits into
branch-3.5from
mergify/bp/branch-3.5/pr-74903
Jun 17, 2026
Merged

[BugFix] Never raise a strict cast overflow error from a null row's data (backport #74903)#74958
wanpengfei-git merged 4 commits into
branch-3.5from
mergify/bp/branch-3.5/pr-74903

Conversation

@mergify

@mergify mergify Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Why I'm doing:

A strict-mode numeric narrowing cast (the AllowThrowException path of UNARY_FN_CAST_VALID,
e.g. cast(x AS INT) when an overflow must error instead of becoming NULL) evaluated the overflow
check on every row of the input, including null rows. The data stored in a null row's slot
is undefined: when a producer leaves garbage there, the check sees an out-of-range value and throws
a spurious exception, failing a query that should succeed — the row is NULL and its value is
irrelevant.

What I'm doing:

  • Add NullAwareInputCheckUnaryFunction (be/src/exprs/unary_function.h). For a nullable input it
    converts all rows but only treats a non-null row's overflow as an error; a null row's data
    can never be the cause of an exception. The hot loop stays branchless and vectorizable (convert
    every row, detect overflow with the non-throwing check AND-ed with the not-null mask and
    OR-accumulated); the throwing check runs only on a cold path entered when a genuine non-null row
    overflows.
  • Wire the strict (AllowThrowException) branch of UNARY_FN_CAST_VALID to use it, passing the
    non-throwing NumberCheck for hot-loop detection and NumberCheckWithThrowException for the cold
    error path.

Bonus: the new implementation is ~1.4-1.6x faster than the old one across nullable/non-nullable
shapes — it avoids materializing and scanning a separate null-mask column and keeps the loop
vectorizable (no per-row branch, no throw in the hot path). Benchmark numbers are in the bench file.

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5

This is an automatic backport of pull request #74903 done by [Mergify](https://mergify.com).

…ata (#74903)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: wanpengfei-git <wanpengfei91@163.com>
(cherry picked from commit 5847dd7)

# Conflicts:
#	be/src/bench/CMakeLists.txt
@mergify mergify Bot added the conflicts label Jun 17, 2026
@mergify

mergify Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of 5847dd7 has failed:

On branch mergify/bp/branch-3.5/pr-74903
Your branch is up to date with 'origin/branch-3.5'.

You are currently cherry-picking commit 5847dd7825.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   be/src/bench/cast_overflow_check_bench.cpp
	modified:   be/src/exprs/cast_expr.cpp
	modified:   be/src/exprs/unary_function.h
	modified:   be/test/CMakeLists.txt
	new file:   be/test/exprs/unary_function_test.cpp
	new file:   test/sql/test_hive/R/test_hive_parquet_dict_null_cast
	new file:   test/sql/test_hive/T/test_hive_parquet_dict_null_cast

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   be/src/bench/CMakeLists.txt

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@wanpengfei-git wanpengfei-git enabled auto-merge (squash) June 17, 2026 11:42
@mergify mergify Bot closed this Jun 17, 2026
auto-merge was automatically disabled June 17, 2026 11:42

Pull request was closed

@mergify

mergify Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@mergify[bot]: Backport conflict, please reslove the conflict and resubmit the pr

@trueeyu trueeyu reopened this Jun 17, 2026
@wanpengfei-git wanpengfei-git enabled auto-merge (squash) June 17, 2026 11:51
trueeyu and others added 3 commits June 17, 2026 20:08
Keep the branch-3.5 bench list and add only the new
cast_overflow_check_bench entry introduced by #74903; the other
bench targets from main do not exist on branch-3.5.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
On branch-3.5 these headers live at their pre-relocation paths:
- base/types/numeric_types.h -> util/numeric_types.h
- column/runtime_type_traits.h -> column/type_traits.h (RunTimeColumnType)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wanpengfei-git wanpengfei-git merged commit 426fdb8 into branch-3.5 Jun 17, 2026
28 of 29 checks passed
@wanpengfei-git wanpengfei-git deleted the mergify/bp/branch-3.5/pr-74903 branch June 17, 2026 13:18
@trueeyu

trueeyu commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@mergify backport branch-3.5-cc

@mergify

mergify Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

backport branch-3.5-cc

✅ Backports have been created

Details

wanpengfei-git added a commit that referenced this pull request Jun 26, 2026
…ata (backport #74903) (backport #74958) (#75362)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: trueeyu <lxhhust350@qq.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: wanpengfei-git <wanpengfei91@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants