Skip to content

[BUG](exec) fix coalesce function output null (#63092)#63996

Merged
yiguolei merged 3 commits into
apache:branch-4.1from
qzsee:fix-coalesce-4.1
Jun 4, 2026
Merged

[BUG](exec) fix coalesce function output null (#63092)#63996
yiguolei merged 3 commits into
apache:branch-4.1from
qzsee:fix-coalesce-4.1

Conversation

@qzsee
Copy link
Copy Markdown
Contributor

@qzsee qzsee commented Jun 2, 2026

What problem does this PR solve?

Cherry-picked from #63092
Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

Issue Number: close #xxx

Example: COALESCE(same_department_income_amount, 0) ==> outputs NULL
(where same_department_income_amount is of type double).

When assigning the value to the result column in the computation, the
assignment is done unconditionally (forced), as in:

```cpp
result_raw_data[row] +=
                    column_raw_data[row] *
                    typename ColumnType::value_type(!(null_map_data[row] | filled_flag[row]));
```
If the argument column column_raw_data's null_map[row] is 1, then the
value stored in column_raw_data[row] is garbage data. This garbage may
contain values such as NaN. If a preceding argument of COALESCE happens
to be assigned NaN, then during subsequent assignments we run into cases
like:

0 * NaN = NaN
num + NaN = NaN

so the assigned result also becomes NaN, which causes value pollution.

By rights the final output should also be NaN, but what is actually
returned is NULL. The reason is that during result serialization/output,
NaN values are emitted as NULL.

```cpp
tatus DataTypeNumberSerDe<T>::_write_column_to_mysql(const IColumn& column,
                                                      MysqlRowBuffer<is_binary_format>& result,
                                                      int row_idx, bool col_const,
                                                      const FormatOptions& options) const {
    //...
    else if constexpr (std::is_same_v<T, float>) {
        if (std::isnan(data[col_index])) {
            // Handle NaN for float, we should push null value
            buf_ret = result.push_null();
        } else {
            buf_ret = result.push_float(data[col_index]);
        }
    }
  //...
}
```
@qzsee qzsee requested a review from yiguolei as a code owner June 2, 2026 06:29
@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?

@yiguolei
Copy link
Copy Markdown
Contributor

yiguolei commented Jun 2, 2026

run buildall

@yiguolei yiguolei closed this Jun 3, 2026
@yiguolei yiguolei reopened this Jun 3, 2026
garenshi added 2 commits June 3, 2026 11:43
@yiguolei
Copy link
Copy Markdown
Contributor

yiguolei commented Jun 3, 2026

run buildall

@yiguolei yiguolei closed this Jun 4, 2026
@yiguolei yiguolei reopened this Jun 4, 2026
@yiguolei yiguolei merged commit 6f482fc into apache:branch-4.1 Jun 4, 2026
27 of 29 checks passed
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.

3 participants