Skip to content
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

feat: implement shiftLeft function push down #5495

Merged
merged 6 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ DAGExpressionAnalyzerHelper::FunctionBuilderMap DAGExpressionAnalyzerHelper::fun
{"bitOr", DAGExpressionAnalyzerHelper::buildBitwiseFunction},
{"bitXor", DAGExpressionAnalyzerHelper::buildBitwiseFunction},
{"bitNot", DAGExpressionAnalyzerHelper::buildBitwiseFunction},
{"bitShiftLeft", DAGExpressionAnalyzerHelper::buildBitwiseFunction},
{"bitShiftRight", DAGExpressionAnalyzerHelper::buildBitwiseFunction},
{"leftUTF8", DAGExpressionAnalyzerHelper::buildLeftUTF8Function},
{"date_add", DAGExpressionAnalyzerHelper::buildDateAddOrSubFunction<DateAdd>},
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/Coprocessor/DAGUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ const std::unordered_map<tipb::ScalarFuncSig, String> scalar_func_map({
{tipb::ScalarFuncSig::DecimalIsFalse, "isFalse"},
{tipb::ScalarFuncSig::DecimalIsFalseWithNull, "isFalseWithNull"},

//{tipb::ScalarFuncSig::LeftShift, "cast"},
{tipb::ScalarFuncSig::LeftShift, "bitShiftLeft"},
{tipb::ScalarFuncSig::RightShift, "bitShiftRight"},

//{tipb::ScalarFuncSig::BitCount, "cast"},
Expand Down
13 changes: 12 additions & 1 deletion dbms/src/Functions/bitShiftLeft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ struct BitShiftLeftImpl<A, B, false>
template <typename Result = ResultType>
static Result apply(A a, B b)
{
return static_cast<Result>(a) << static_cast<Result>(b);
// It is an undefined behavior for shift operation in c++ that the right operand is negative or greater than
// or equal to the number of digits of the bits in the (promoted) left operand.
// See https://en.cppreference.com/w/cpp/language/operator_arithmetic for details.
if (static_cast<Result>(b) >= std::numeric_limits<decltype(static_cast<Result>(a))>::digits)
{
return static_cast<Result>(0);
}
// Note that we do not consider the case that the right operand is negative,
// since other types will all be cast to uint64 before shift operation
// according to DAGExpressionAnalyzerHelper::buildBitwiseFunction.
// Therefore, we simply suppress clang-tidy checking here.
return static_cast<Result>(a) << static_cast<Result>(b); // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult)
}
template <typename Result = ResultType>
static Result apply(A, B, UInt8 &)
Expand Down
Loading