-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[enhancement](exception) add exception structure and using unique ptr in VExplodeBitmapTableFunction #17531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[enhancement](exception) add exception structure and using unique ptr in VExplodeBitmapTableFunction #17531
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
02d835e
[enhancement](exception) add exception structure
Doris-Extras fd4e9b2
f
Doris-Extras 6c8868a
f
Doris-Extras 1fdf012
f
Doris-Extras c6650d9
f
Doris-Extras 8b17d26
f
Doris-Extras d479c3d
f
Doris-Extras de4da11
f
Doris-Extras c540ee8
f
Doris-Extras f199bfa
f
Doris-Extras cf406eb
f
Doris-Extras 68ad1a6
f
Doris-Extras f627d24
f
Doris-Extras 71c883b
f
Doris-Extras 6bfa00f
f
Doris-Extras de58e5b
f
Doris-Extras 625ead5
f
Doris-Extras 30aa395
Update be/src/vec/exprs/table_function/vexplode_bitmap.h
yiguolei cd6ae41
Update be/src/common/exception.h
yiguolei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "common/exception.h" | ||
|
|
||
| #include "util/stack_util.h" | ||
| namespace doris { | ||
|
|
||
| Exception::Exception(int code, const std::string_view msg) { | ||
| _code = code; | ||
| _err_msg = std::make_unique<ErrMsg>(); | ||
| _err_msg->_msg = msg; | ||
| _err_msg->_stack = get_stack_trace(); | ||
| } | ||
| Exception::Exception(const Exception& nested, int code, const std::string_view msg) { | ||
| _code = code; | ||
| _err_msg = std::make_unique<ErrMsg>(); | ||
| _err_msg->_msg = msg; | ||
| _err_msg->_stack = get_stack_trace(); | ||
| _nested_excption = std::make_unique<Exception>(); | ||
| _nested_excption->_code = nested._code; | ||
| _nested_excption->_err_msg = std::make_unique<ErrMsg>(); | ||
| _nested_excption->_err_msg->_msg = nested._err_msg->_msg; | ||
| _nested_excption->_err_msg->_stack = nested._err_msg->_stack; | ||
| } | ||
|
|
||
| } // namespace doris |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "common/status.h" | ||
|
|
||
| namespace doris { | ||
|
|
||
| class Exception : public std::exception { | ||
| public: | ||
| Exception() : _code(ErrorCode::OK) {} | ||
| Exception(int code, const std::string_view 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); | ||
|
|
||
| // Format message with fmt::format, like the logging functions. | ||
| template <typename... Args> | ||
| Exception(int code, const std::string_view fmt, Args&&... args) | ||
| : Exception(code, fmt::format(fmt, std::forward<Args>(args)...)) {} | ||
|
|
||
| std::string code_as_string() const { | ||
| return (int)_code >= 0 ? doris::to_string(static_cast<TStatusCode::type>(_code)) | ||
| : fmt::format("E{}", (int16_t)_code); | ||
| } | ||
|
|
||
| int code() const { return _code; } | ||
|
|
||
| std::string to_string() const; | ||
|
|
||
| friend std::ostream& operator<<(std::ostream& ostr, const Exception& exp); | ||
|
|
||
| private: | ||
| int _code; | ||
| struct ErrMsg { | ||
| std::string _msg; | ||
| std::string _stack; | ||
| }; | ||
| std::unique_ptr<ErrMsg> _err_msg; | ||
| std::unique_ptr<Exception> _nested_excption; | ||
| }; | ||
|
|
||
| inline std::ostream& operator<<(std::ostream& ostr, const Exception& exp) { | ||
| ostr << '[' << exp.code_as_string() << "] "; | ||
| ostr << (exp._err_msg ? exp._err_msg->_msg : ""); | ||
| if (exp._err_msg && !exp._err_msg->_stack.empty()) { | ||
| ostr << '\n' << exp._err_msg->_stack; | ||
| } | ||
| if (exp._nested_excption != nullptr) { | ||
| ostr << '\n' << "Caused by:" << *exp._nested_excption; | ||
| } | ||
| return ostr; | ||
| } | ||
|
|
||
| inline std::string Exception::to_string() const { | ||
| std::stringstream ss; | ||
| ss << *this; | ||
| return ss.str(); | ||
| } | ||
|
|
||
| } // namespace doris | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "common/exception.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| namespace doris { | ||
|
|
||
| class ExceptionTest : public testing::Test {}; | ||
|
|
||
| TEST_F(ExceptionTest, OK) { | ||
| // default | ||
| try { | ||
| throw doris::Exception(); | ||
| } catch (doris::Exception& e) { | ||
| EXPECT_TRUE(e.code() == ErrorCode::OK); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(ExceptionTest, SingleError) { | ||
| try { | ||
| throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug"); | ||
| } catch (doris::Exception& e) { | ||
| EXPECT_TRUE(e.to_string().find("OS_ERROR") != std::string::npos); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(ExceptionTest, NestedError) { | ||
| try { | ||
| throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug"); | ||
| } catch (doris::Exception& e1) { | ||
| EXPECT_TRUE(e1.to_string().find("OS_ERROR") != std::string::npos); | ||
| try { | ||
| throw doris::Exception(e1, ErrorCode::INVALID_ARGUMENT, "test INVALID_ARGUMENT"); | ||
| } catch (doris::Exception& e2) { | ||
| EXPECT_TRUE(e2.to_string().find("OS_ERROR") != std::string::npos); | ||
| EXPECT_TRUE(e2.to_string().find("INVALID_ARGUMENT") != std::string::npos); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } // namespace doris |
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.
Uh oh!
There was an error while loading. Please reload this page.