From d78ba9cdcfeb5b62c617aa30ae959ba615e2ab16 Mon Sep 17 00:00:00 2001 From: zhangstar333 <87313068+zhangstar333@users.noreply.github.com> Date: Sun, 15 May 2022 23:56:01 +0800 Subject: [PATCH] [fix](function) fix last_value get wrong result when have order by clause (#9247) --- .../aggregate_function_window.h | 21 +-- be/test/vec/function/function_bitmap_test.cpp | 135 +++++++----------- .../apache/doris/analysis/AnalyticExpr.java | 5 +- .../correctness/test_last_value_window.out | 8 ++ .../correctness/test_last_value_window.groovy | 51 +++++++ 5 files changed, 127 insertions(+), 93 deletions(-) create mode 100644 regression-test/data/correctness/test_last_value_window.out create mode 100644 regression-test/suites/correctness/test_last_value_window.groovy diff --git a/be/src/vec/aggregate_functions/aggregate_function_window.h b/be/src/vec/aggregate_functions/aggregate_function_window.h index 95fedc3e13bbb7c..2a9bebfd112aded 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_window.h +++ b/be/src/vec/aggregate_functions/aggregate_function_window.h @@ -183,12 +183,12 @@ struct CopiedValue : public Value { std::string _copied_value; }; -template +template struct LeadAndLagData { public: bool has_init() const { return _is_init; } - static constexpr bool nullable = is_nullable; + static constexpr bool nullable = result_is_nullable; void set_null_if_need() { if (!_has_value) { @@ -204,7 +204,7 @@ struct LeadAndLagData { } void insert_result_into(IColumn& to) const { - if constexpr (is_nullable) { + if constexpr (result_is_nullable) { if (_data_value.is_null()) { auto& col = assert_cast(to); col.insert_default(); @@ -231,7 +231,7 @@ struct LeadAndLagData { } void set_value(const IColumn** columns, int64_t pos) { - if constexpr (is_nullable) { + if (is_column_nullable(*columns[0])) { const auto* nullable_column = assert_cast(columns[0]); if (nullable_column && nullable_column->is_null_at(pos)) { _data_value.set_null(true); @@ -501,7 +501,7 @@ class WindowFunctionData final }; template