Add bitamp_to_string function (#2731)
This CL changes: 1. add function bitmap_to_string and bitmap_from_string, which will convert a bitmap to/from string which contains all bit in bitmap 2. add function murmur_hash3_32, which will compute murmur hash for input strings 3. make the function cast float to string the same with user result logic
This commit is contained in:
@ -20,6 +20,8 @@
|
||||
#include "exprs/anyval_util.h"
|
||||
#include "util/bitmap.h"
|
||||
#include "util/string_parser.hpp"
|
||||
#include "gutil/strings/split.h"
|
||||
#include "gutil/strings/numbers.h"
|
||||
|
||||
namespace doris {
|
||||
|
||||
@ -425,7 +427,40 @@ StringVal BitmapFunctions::bitmap_and(FunctionContext* ctx, const StringVal& lhs
|
||||
bitmap.intersect(RoaringBitmap((char*)rhs.ptr));
|
||||
}
|
||||
|
||||
StringVal result(ctx,bitmap.size());
|
||||
StringVal result(ctx, bitmap.size());
|
||||
bitmap.serialize((char*)result.ptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
StringVal BitmapFunctions::bitmap_to_string(FunctionContext* ctx, const StringVal& input) {
|
||||
if (input.is_null) {
|
||||
return StringVal::null();
|
||||
}
|
||||
RoaringBitmap bitmap_obj;
|
||||
RoaringBitmap* bitmap = &bitmap_obj;
|
||||
if (input.len == 0) {
|
||||
bitmap = (RoaringBitmap*)input.ptr;
|
||||
} else {
|
||||
bitmap_obj.deserialize((const char*)input.ptr);
|
||||
}
|
||||
|
||||
std::string str = bitmap->to_string();
|
||||
return AnyValUtil::from_string_temp(ctx, str);
|
||||
}
|
||||
|
||||
StringVal BitmapFunctions::bitmap_from_string(FunctionContext* ctx, const StringVal& input) {
|
||||
if (input.is_null) {
|
||||
return StringVal::null();
|
||||
}
|
||||
|
||||
std::vector<uint32_t> bits;
|
||||
if (!SplitStringAndParse({(const char*)input.ptr, input.len}, ",", &safe_strtou32, &bits)) {
|
||||
return StringVal::null();
|
||||
}
|
||||
|
||||
RoaringBitmap bitmap(bits);
|
||||
|
||||
StringVal result(ctx, bitmap.size());
|
||||
bitmap.serialize((char*)result.ptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user