diff --git a/be/src/vec/common/string_ref.h b/be/src/vec/common/string_ref.h index 587924b45e31a7..72a7a911210f95 100644 --- a/be/src/vec/common/string_ref.h +++ b/be/src/vec/common/string_ref.h @@ -22,10 +22,10 @@ // IWYU pragma: no_include #include -#include #include #include +#include #include #include #include @@ -38,7 +38,6 @@ #include "util/hash_util.hpp" #include "util/slice.h" #include "util/sse_util.hpp" -#include "vec/common/string_ref.h" #include "vec/common/unaligned.h" #include "vec/core/types.h" @@ -150,7 +149,8 @@ inline bool memequalSSE2Wide(const char* p1, const char* p2, size_t size) { // - s1/n1: ptr/len for the first string // - s2/n2: ptr/len for the second string // - len: min(n1, n2) - this can be more cheaply passed in by the caller -inline int string_compare(const char* s1, int64_t n1, const char* s2, int64_t n2, int64_t len) { +PURE inline int string_compare(const char* s1, int64_t n1, const char* s2, int64_t n2, + int64_t len) { DCHECK_EQ(len, std::min(n1, n2)); #if defined(__SSE4_2__) || defined(__aarch64__) while (len >= sse_util::CHARS_PER_128_BIT_REGISTER) { @@ -199,8 +199,8 @@ struct StringRef { std::string to_string() const { return std::string(data, size); } std::string debug_string() const { return to_string(); } - std::string_view to_string_view() const { return std::string_view(data, size); } - Slice to_slice() const { return doris::Slice(data, size); } + std::string_view to_string_view() const { return {data, size}; } + Slice to_slice() const { return {data, size}; } // this is just for show, e.g. print data to error log, to avoid print large string. std::string to_prefix(size_t length) const { return std::string(data, std::min(length, size)); } @@ -209,7 +209,7 @@ struct StringRef { operator std::string_view() const { return std::string_view {data, size}; } StringRef substring(int start_pos, int new_len) const { - return StringRef(data + start_pos, (new_len < 0) ? (size - start_pos) : new_len); + return {data + start_pos, (new_len < 0) ? (size - start_pos) : new_len}; } StringRef substring(int start_pos) const { return substring(start_pos, size - start_pos); } @@ -255,7 +255,9 @@ struct StringRef { } } - return string_compare(this->data, this->size, other.data, other.size, l); + // string_compare doesn't have sign result + int cmp_result = string_compare(this->data, this->size, other.data, other.size, l); + return (cmp_result > 0) - (cmp_result < 0); } void replace(const char* ptr, int len) { @@ -363,8 +365,8 @@ inline size_t hash_less_than8(const char* data, size_t size) { inline size_t hash_less_than16(const char* data, size_t size) { if (size > 8) { - doris::vectorized::UInt64 a = unaligned_load(data); - doris::vectorized::UInt64 b = unaligned_load(data + size - 8); + auto a = unaligned_load(data); + auto b = unaligned_load(data + size - 8); return hash_len16(a, rotate_by_at_least1(b + size, size)) ^ b; } @@ -388,13 +390,13 @@ struct CRC32Hash { size_t res = -1ULL; do { - doris::vectorized::UInt64 word = unaligned_load(pos); + auto word = unaligned_load(pos); res = _mm_crc32_u64(res, word); pos += 8; } while (pos + 8 < end); - doris::vectorized::UInt64 word = unaligned_load( + auto word = unaligned_load( end - 8); /// I'm not sure if this is normal. res = _mm_crc32_u64(res, word); diff --git a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function.out b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function.out index e3ca494c632fb9..69ce99277fa878 100644 Binary files a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function.out and b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function.out differ diff --git a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function.groovy b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function.groovy index 64798978d3b94b..f8fe485f96732e 100644 --- a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function.groovy @@ -358,4 +358,7 @@ suite("test_string_function", "arrow_flight_sql") { qt_sql_func_char9 """ select char(0) = ' '; """ qt_sql_func_char10 """ select char(0) = '\0'; """ + qt_strcmp1 """ select strcmp('a', 'abc'); """ + qt_strcmp2 """ select strcmp('abc', 'abc'); """ + qt_strcmp3 """ select strcmp('abcd', 'abc'); """ }