diff --git a/be/src/common/exception.h b/be/src/common/exception.h index 92d49495a4f4e4..eb87b43503d36c 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -38,6 +38,7 @@ class Exception : public std::exception { public: Exception() : _code(ErrorCode::OK) {} Exception(int code, const std::string_view msg); + Exception(const Status& status) : Exception(status.code(), status.msg()) {} // add nested exception as first param, or the template may could not find // the correct method for ...args Exception(const Exception& nested, int code, const std::string_view msg); diff --git a/be/src/vec/aggregate_functions/aggregate_function_sort.h b/be/src/vec/aggregate_functions/aggregate_function_sort.h index 39d7fd184f5688..4a103db15c82f8 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_sort.h +++ b/be/src/vec/aggregate_functions/aggregate_function_sort.h @@ -75,8 +75,11 @@ struct AggregateFunctionSortData { PBlock pblock; size_t uncompressed_bytes = 0; size_t compressed_bytes = 0; - block.serialize(state->be_exec_version(), &pblock, &uncompressed_bytes, &compressed_bytes, - segment_v2::CompressionTypePB::SNAPPY); + auto st = block.serialize(state->be_exec_version(), &pblock, &uncompressed_bytes, + &compressed_bytes, segment_v2::CompressionTypePB::SNAPPY); + if (!st.ok()) { + throw doris::Exception(st); + } write_string_binary(pblock.SerializeAsString(), buf); } @@ -88,7 +91,11 @@ struct AggregateFunctionSortData { PBlock pblock; pblock.ParseFromString(data); auto st = block.deserialize(pblock); - CHECK(st.ok()); + // If memory allocate failed during deserialize, st is not ok, throw exception here to + // stop the query. + if (!st.ok()) { + throw doris::Exception(st); + } } void add(const IColumn** columns, size_t columns_num, size_t row_num) {