Skip to content

[fix](function) Fix BE crash in trim when input column is ColumnConst - #67736

Open
LLLLLL302311 wants to merge 1 commit into
apache:masterfrom
LLLLLL302311:fix_trim_const_pr
Open

[fix](function) Fix BE crash in trim when input column is ColumnConst#67736
LLLLLL302311 wants to merge 1 commit into
apache:masterfrom
LLLLLL302311:fix_trim_const_pr

Conversation

@LLLLLL302311

Copy link
Copy Markdown

What problem does this PR solve?

Problem Summary:

Trim1Impl / Trim2Impl directly assert_cast<const ColumnString*> the input column. When the column reaching the implementation is a ColumnConst — which can happen on pushdown / materialization paths that invoke the function implementation directly, bypassing the const-unwrapping done by default_implementation_for_constant_arguments — the assert_cast hits the wrong type and aborts the BE (undefined behavior in release builds).

The fix unpacks the const first via unpack_if_const, then uses check_and_get_column, which returns nullptr on a type mismatch and falls through to the existing RuntimeError branch instead of crashing. This matches the defensive pattern used elsewhere in the codebase and does not change behavior on the normal column path.

Release note

Fix BE crash in trim/ltrim/rtrim when the input column is a ColumnConst.

Check List (For Author)

  • Test
    • Unit Test
  • Behavior changed:
    • No.
  • Does this need documentation?
    • No.

Trim1Impl/Trim2Impl directly assert_cast<const ColumnString*> on the input
column. When the input reaching the implementation is a ColumnConst (which can
happen on pushdown / materialization paths that invoke the function
implementation directly, bypassing the const-unwrapping in
default_implementation_for_constant_arguments), the assert_cast hits the wrong
type and aborts the BE (undefined behavior in release builds).

Unpack the const first via unpack_if_const, and use check_and_get_column, which
returns nullptr on a type mismatch and falls through to the existing
RuntimeError branch instead of crashing. This matches the defensive pattern used
elsewhere in the codebase and does not change behavior on the normal column path.

Add a regression test that builds a ColumnConst block and calls execute_impl
directly, since the normal execute() entry unwraps all-constant arguments before
reaching the implementation and cannot reproduce the crash.

Signed-off-by: lijinghan.1029 <lijinghan.1029@jd.com>

Conflicts:
	be/test/exprs/function/function_string_test.cpp
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants