This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new ca9eb562330 [Fix](functions) fix strcmp return value #34565
ca9eb562330 is described below
commit ca9eb56233006846282a0aca1948d48ffc6b998e
Author: zclllyybb <[email protected]>
AuthorDate: Sun May 12 09:27:32 2024 +0800
[Fix](functions) fix strcmp return value #34565
---
be/src/vec/common/string_ref.h | 24 +++++++++++----------
.../string_functions/test_string_function.out | Bin 4162 -> 4217 bytes
.../string_functions/test_string_function.groovy | 3 +++
3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/be/src/vec/common/string_ref.h b/be/src/vec/common/string_ref.h
index 587924b45e3..72a7a911210 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 <crc32intrin.h>
#include <glog/logging.h>
-#include <stdint.h>
#include <algorithm>
#include <climits>
+#include <cstdint>
#include <cstring>
#include <ostream>
#include <string>
@@ -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<doris::vectorized::UInt64>(data);
- doris::vectorized::UInt64 b =
unaligned_load<doris::vectorized::UInt64>(data + size - 8);
+ auto a = unaligned_load<doris::vectorized::UInt64>(data);
+ auto b = unaligned_load<doris::vectorized::UInt64>(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<doris::vectorized::UInt64>(pos);
+ auto word = unaligned_load<doris::vectorized::UInt64>(pos);
res = _mm_crc32_u64(res, word);
pos += 8;
} while (pos + 8 < end);
- doris::vectorized::UInt64 word =
unaligned_load<doris::vectorized::UInt64>(
+ auto word = unaligned_load<doris::vectorized::UInt64>(
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 e3ca494c632..69ce99277fa 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 64798978d3b..f8fe485f967 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'); """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]