branch-4.1: [BUG](exec) fix coalesce function output null #63092#63808
Open
github-actions[bot] wants to merge 1 commit into
Open
branch-4.1: [BUG](exec) fix coalesce function output null #63092#63808github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
### 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>
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-picked from #63092