Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions be/src/exprs/string_functions.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ void StringFunctions::init() {}
size_t get_char_len(const StringVal& str, std::vector<size_t>* str_index) {
size_t char_len = 0;
for (size_t i = 0, char_size = 0; i < str.len; i += char_size) {
char_size = get_utf8_byte_length((unsigned)(str.ptr)[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(str.ptr)[i]];
str_index->push_back(i);
++char_len;
}
Expand DownExpand Up@@ -65,7 +65,7 @@ StringVal StringFunctions::substring(FunctionContext* context, const StringVal&
size_t byte_pos = 0;
std::vector<size_t> index;
for (size_t i = 0, char_size = 0; i < str.len; i += char_size) {
char_size = get_utf8_byte_length((unsigned)(str.ptr)[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(str.ptr)[i]];
index.push_back(i);
if (pos.val > 0 && index.size() > pos.val + len.val) {
break;
Expand DownExpand Up@@ -328,7 +328,7 @@ IntVal StringFunctions::char_utf8_length(FunctionContext* context, const StringV
}
size_t char_len = 0;
for (size_t i = 0, char_size = 0; i < str.len; i += char_size) {
char_size = get_utf8_byte_length((unsigned)(str.ptr)[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(str.ptr)[i]];
++char_len;
}
return IntVal(char_len);
Expand DownExpand Up@@ -429,7 +429,7 @@ IntVal StringFunctions::instr(FunctionContext* context, const StringVal& str,
if (loc > 0) {
size_t char_len = 0;
for (size_t i = 0, char_size = 0; i < loc; i += char_size) {
char_size = get_utf8_byte_length((unsigned)(str.ptr)[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(str.ptr)[i]];
++char_len;
}
loc = char_len;
Expand DownExpand Up@@ -477,7 +477,7 @@ IntVal StringFunctions::locate_pos(FunctionContext* context, const StringVal& su
// Hive returns the position in the original string starting from 1.
size_t char_len = 0;
for (size_t i = 0, char_size = 0; i < match_pos; i += char_size) {
char_size = get_utf8_byte_length((unsigned)(adjusted_str.ptr)[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(adjusted_str.ptr)[i]];
++char_len;
}
match_pos = char_len;
Expand Down
29 changes: 11 additions & 18 deletions be/src/util/simd/vstring_function.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,23 +30,16 @@

namespace doris {

static size_t get_utf8_byte_length(unsigned char byte) {
size_t char_size = 0;
if (byte >= 0xFC) {
char_size = 6;
} else if (byte >= 0xF8) {
char_size = 5;
} else if (byte >= 0xF0) {
char_size = 4;
} else if (byte >= 0xE0) {
char_size = 3;
} else if (byte >= 0xC0) {
char_size = 2;
} else {
char_size = 1;
}
return char_size;
}
static constexpr std::array<uint8, 256> UTF8_BYTE_LENGTH = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6};

namespace simd {

Expand DownExpand Up@@ -149,7 +142,7 @@ class VStringFunctions {
}
} else {
for (size_t i = 0, char_size = 0; i < str.len; i += char_size) {
char_size = get_utf8_byte_length((unsigned)(str.ptr)[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(str.ptr)[i]];
std::copy(str.ptr + i, str.ptr + i + char_size, dst.ptr + str.len - i - char_size);
}
}
Expand Down
22 changes: 4 additions & 18 deletions be/src/vec/functions/function_string.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,24 +58,10 @@

namespace doris::vectorized {

inline size_t get_utf8_byte_length(unsigned char byte) {
size_t char_size = 0;
if (byte < 0xC0) {
char_size = 1;
} else if (byte >= 0xF0) {
char_size = 4;
} else if (byte >= 0xE0) {
char_size = 3;
} else {
char_size = 2;
}
return char_size;
}

inline size_t get_char_len(const std::string_view& str, std::vector<size_t>* str_index) {
size_t char_len = 0;
for (size_t i = 0, char_size = 0; i < str.length(); i += char_size) {
char_size = get_utf8_byte_length(str[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)str[i]];
str_index->push_back(i);
++char_len;
}
Expand All@@ -85,7 +71,7 @@ inline size_t get_char_len(const std::string_view& str, std::vector<size_t>* str
inline size_t get_char_len(const StringVal& str, std::vector<size_t>* str_index) {
size_t char_len = 0;
for (size_t i = 0, char_size = 0; i < str.len; i += char_size) {
char_size = get_utf8_byte_length((unsigned)(str.ptr)[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(str.ptr)[i]];
str_index->push_back(i);
++char_len;
}
Expand All@@ -95,7 +81,7 @@ inline size_t get_char_len(const StringVal& str, std::vector<size_t>* str_index)
inline size_t get_char_len(const StringValue& str, size_t end_pos) {
size_t char_len = 0;
for (size_t i = 0, char_size = 0; i < std::min(str.len, end_pos); i += char_size) {
char_size = get_utf8_byte_length((unsigned)(str.ptr)[i]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(str.ptr)[i]];
++char_len;
}
return char_len;
Expand DownExpand Up@@ -192,7 +178,7 @@ struct SubstringUtil {
size_t byte_pos = 0;
index.clear();
for (size_t j = 0, char_size = 0; j < str_size; j += char_size) {
char_size = get_utf8_byte_length((unsigned)(raw_str)[j]);
char_size = UTF8_BYTE_LENGTH[(unsigned char)(raw_str)[j]];
index.push_back(j);
if (start[i] > 0 && index.size() > start[i] + len[i]) {
break;
Expand Down