Skip to content

branch-4.1: [BUG](exec) fix coalesce function output null #63092#63808

Open
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-63092-branch-4.1
Open

branch-4.1: [BUG](exec) fix coalesce function output null #63092#63808
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-63092-branch-4.1

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Cherry-picked from #63092

### What problem does this PR solve?

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]);
        }
    } 
  //...
}
```


Co-authored-by: garenshi <garenshi@tencent.com>
@github-actions github-actions Bot requested a review from yiguolei as a code owner May 28, 2026 07:25
@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?

@hello-stephen
Copy link
Copy Markdown
Contributor

run buildall

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