Skip to content

Commit

Permalink
feat: bit type transfer to long
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-2023 authored and wy1433 committed Apr 24, 2024
1 parent 8b1f354 commit 078d421
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/expr/internal_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ExprValue pi(const std::vector<ExprValue>& input);
ExprValue greatest(const std::vector<ExprValue>& input);
ExprValue least(const std::vector<ExprValue>& input);
ExprValue pow(const std::vector<ExprValue>& input);
ExprValue bit_count(const std::vector<ExprValue>& input);
//string functions
ExprValue length(const std::vector<ExprValue>& input);
ExprValue bit_length(const std::vector<ExprValue>& input);
Expand Down
2 changes: 1 addition & 1 deletion include/sqlparser/sql_parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -4028,7 +4028,7 @@ FloatingPointType:
BitValueType:
BIT
{
$$ = MYSQL_TYPE_BIT;
$$ = MYSQL_TYPE_LONG;
}
;

Expand Down
1 change: 1 addition & 0 deletions src/expr/fn_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void FunctionManager::register_operators() {
register_object_ret("least", least, pb::DOUBLE);
register_object_ret("ceil", ceil, pb::INT64);
register_object_ret("ceiling", ceil, pb::INT64);
register_object_ret("bit_count", bit_count, pb::INT64);

// str funcs
register_object_ret("length", length, pb::INT64);
Expand Down
15 changes: 15 additions & 0 deletions src/expr/internal_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,21 @@ ExprValue bit_length(const std::vector<ExprValue>& input) {
tmp._u.uint32_val = input[0].get_string().size() * 8;
return tmp;
}
ExprValue bit_count(const std::vector<ExprValue>& input) {
if (input.size() != 1 || input[0].is_null()) {
return ExprValue::Null();
}
ExprValue tmp = input[0];
tmp.cast_to(pb::UINT64);
ExprValue res(pb::INT64);
while (tmp._u.uint64_val) {
if (tmp._u.uint64_val & 1) {
res._u.int64_val += 1;
}
tmp._u.uint64_val >>= 1;
}
return res;
}

ExprValue lower(const std::vector<ExprValue>& input) {
if (input.size() == 0 || input[0].is_null()) {
Expand Down

0 comments on commit 078d421

Please sign in to comment.