[feature](function) support quote string function #33055
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
#include <math.h>
|
||||
#include <re2/stringpiece.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <string_view>
|
||||
|
||||
#include "common/status.h"
|
||||
@ -57,6 +58,30 @@ struct StringASCII {
|
||||
}
|
||||
};
|
||||
|
||||
struct NameQuote {
|
||||
static constexpr auto name = "quote";
|
||||
};
|
||||
|
||||
struct NameQuoteImpl {
|
||||
static Status vector(const ColumnString::Chars& data, const ColumnString::Offsets& offsets,
|
||||
ColumnString::Chars& res_data, ColumnString::Offsets& res_offsets) {
|
||||
size_t offset_size = offsets.size();
|
||||
size_t pos = 0;
|
||||
res_offsets.resize(offset_size);
|
||||
res_data.resize(data.size() + offset_size * 2);
|
||||
for (int i = 0; i < offset_size; i++) {
|
||||
const unsigned char* raw_str = &data[offsets[i - 1]];
|
||||
ColumnString::Offset size = offsets[i] - offsets[i - 1];
|
||||
res_data[pos] = '\'';
|
||||
std::memcpy(res_data.data() + pos + 1, raw_str, size);
|
||||
res_data[pos + size + 1] = '\'';
|
||||
pos += size + 2;
|
||||
res_offsets[i] = pos;
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
};
|
||||
|
||||
struct NameStringLenght {
|
||||
static constexpr auto name = "length";
|
||||
};
|
||||
@ -1052,6 +1077,8 @@ using FunctionStringLocate =
|
||||
using FunctionStringFindInSet =
|
||||
FunctionBinaryToType<DataTypeString, DataTypeString, StringFindInSetImpl, NameFindInSet>;
|
||||
|
||||
using FunctionQuote = FunctionStringToString<NameQuoteImpl, NameQuote>;
|
||||
|
||||
using FunctionToLower = FunctionStringToString<TransferImpl<NameToLower>, NameToLower>;
|
||||
|
||||
using FunctionToUpper = FunctionStringToString<TransferImpl<NameToUpper>, NameToUpper>;
|
||||
@ -1082,6 +1109,7 @@ void register_function_string(SimpleFunctionFactory& factory) {
|
||||
factory.register_function<FunctionStringFindInSet>();
|
||||
factory.register_function<FunctionStringLocate>();
|
||||
factory.register_function<FunctionStringLocatePos>();
|
||||
factory.register_function<FunctionQuote>();
|
||||
factory.register_function<FunctionReverseCommon>();
|
||||
factory.register_function<FunctionUnHex>();
|
||||
factory.register_function<FunctionToLower>();
|
||||
|
||||
Reference in New Issue
Block a user