-
Notifications
You must be signed in to change notification settings - Fork 409
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
Push down ROUND(x)
on decimal types
#2492
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
60a2120
feat: implement round(x).
riteme 3bbc331
test: integration test.
riteme 6c8070c
refactor: fix review.
riteme 51e7379
fix: dispatch fails.
riteme 097e113
test: unit test.
riteme 1decc46
style: remove blank line.
riteme de47110
Merge branch 'master' into function-round
riteme fee29ed
refactor: safeUnsignedAbs -> toSafeUnsigned.
riteme cbe78d6
Merge branch 'master' into function-round
riteme 210bc74
fix: review.
riteme 478bbb8
Merge branch 'master' into function-round
riteme 6392025
refactor: EXPECT -> assert.
riteme af649b2
Merge branch 'function-round' of github.com:riteme/tics into function…
riteme 5af43c1
fix: review.
riteme 45f811f
Merge branch 'master' into function-round
riteme 01327c4
style: maybe_unused.
riteme 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 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,48 @@ | ||
#pragma once | ||
|
||
#include <common/types.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
// toSafeUnsigned evaluates absolute value of argument `value` and cast it to unsigned type of `To`. | ||
// it guarantees that no undefined behavior will occur and exact result can be represented by unsigned `To`. | ||
template <typename To, typename From> | ||
constexpr make_unsigned_t<To> toSafeUnsigned(const From & value) | ||
{ | ||
static_assert(is_integer_v<From>, "type From must be integral"); | ||
static_assert(is_integer_v<To>, "type To must be integral"); | ||
|
||
using ReturnType = make_unsigned_t<To>; | ||
|
||
static_assert(actual_size_v<ReturnType> >= actual_size_v<From>, "type unsigned To can't hold all values of type From"); | ||
|
||
if constexpr (is_signed_v<From>) | ||
{ | ||
if constexpr (is_boost_number_v<ReturnType>) | ||
{ | ||
// assert that negation of std::numeric_limits<From>::min() will not result in overflow. | ||
// TODO: find credible source that describes numeric limits of boost multiprecision *checked* integers. | ||
static_assert(-std::numeric_limits<From>::max() == std::numeric_limits<From>::min()); | ||
return static_cast<ReturnType>(boost::multiprecision::abs(value)); | ||
} | ||
else | ||
{ | ||
if (value < 0) | ||
{ | ||
// both signed to unsigned conversion [1] and negation of unsigned integers [2] are well defined in C++. | ||
// | ||
// see: | ||
// [1]: https://en.cppreference.com/w/c/language/conversion#Integer_conversions | ||
// [2]: https://en.cppreference.com/w/cpp/language/operator_arithmetic#Unary_arithmetic_operators | ||
return -static_cast<ReturnType>(value); | ||
} | ||
else | ||
return static_cast<ReturnType>(value); | ||
} | ||
} | ||
else | ||
return static_cast<ReturnType>(value); | ||
} | ||
|
||
} // namespace DB |
This file contains 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 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 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 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 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original implementation of
round
from Clickhouse employed some SIMD computations, buttidbRoundWithFrac
currently doesn't make use of them at all.Maybe reset
RoundReal
andRoundInt
to"round"
in this PR for better performance?