35 if (
'A' <= c && c <=
'Z') {
36 return 'a' + (c -
'A');
42 const int32_t str_len,
44 const int32_t pat_len) {
46 int search_len = str_len - pat_len + 1;
47 for (i = 0; i < search_len; ++i) {
48 for (j = 0; j < pat_len && pattern[j] == str[j + i]; ++j) {
58 const int32_t str_len,
60 const int32_t pat_len) {
62 int search_len = str_len - pat_len + 1;
63 for (i = 0; i < search_len; ++i) {
64 for (j = 0; j < pat_len && pattern[j] ==
lowercase(str[j + i]); ++j) {
73 #define STR_LIKE_SIMPLE_NULLABLE(base_func) \
74 extern "C" RUNTIME_EXPORT DEVICE int8_t base_func##_nullable(const char* lhs, \
75 const int32_t lhs_len, \
77 const int32_t rhs_len, \
78 const int8_t bool_null) { \
82 return base_func(lhs, lhs_len, rhs, rhs_len) ? 1 : 0; \
88 #undef STR_LIKE_SIMPLE_NULLABLE
93 const int32_t str_len,
95 const int32_t pat_len,
96 const char escape_char,
97 const bool is_ilike) {
100 const char* p = pattern;
103 while (slen > 0 && plen > 0) {
104 if (*p == escape_char) {
111 if ((!is_ilike && *s != *p) || (is_ilike &&
lowercase(*s) != *p)) {
114 }
else if (*p ==
'%') {
122 }
else if (*p ==
'_') {
137 if (*p == escape_char) {
148 if (firstpat ==
'[' && *p != escape_char) {
149 const char* pp = p + 1;
150 int pplen = plen - 1;
151 while (pplen > 0 && *pp !=
']') {
152 if ((!is_ilike && *s == *pp) || (is_ilike &&
lowercase(*s) == *pp)) {
162 }
else if ((!is_ilike && *s == firstpat) ||
163 (is_ilike &&
lowercase(*s) == firstpat)) {
176 }
else if (*p ==
'_') {
182 }
else if (*p ==
'[') {
183 const char* pp = p + 1;
184 int pplen = plen - 1;
186 while (pplen > 0 && *pp !=
']') {
187 if ((!is_ilike && *s == *pp) || (is_ilike &&
lowercase(*s) == *pp)) {
199 for (x = pp + 1; *x !=
']' && pplen > 0; x++, pplen--) {
211 }
else if ((!is_ilike && *s != *p) || (is_ilike &&
lowercase(*s) != *p)) {
222 while (plen > 0 && *p ==
'%') {
245 const int32_t str_len,
247 const int32_t pat_len,
248 const char escape_char) {
256 const int32_t str_len,
258 const int32_t pat_len,
259 const char escape_char) {
267 const int32_t s1_len,
269 const int32_t s2_len) {
270 const char* s1_ = s1;
271 const char* s2_ = s2;
273 while (s1_ < s1 + s1_len && s2_ < s2 + s2_len && *s1_ == *s2_) {
278 unsigned char c1 = (s1_ < s1 + s1_len) ? (*(
unsigned char*)s1_) : 0;
279 unsigned char c2 = (s2_ < s2 + s2_len) ? (*(
unsigned char*)s2_) : 0;
284 #define STR_LIKE_NULLABLE(base_func) \
285 extern "C" RUNTIME_EXPORT DEVICE int8_t base_func##_nullable(const char* lhs, \
286 const int32_t lhs_len, \
288 const int32_t rhs_len, \
289 const char escape_char, \
290 const int8_t bool_null) { \
291 if (!lhs || !rhs) { \
294 return base_func(lhs, lhs_len, rhs, rhs_len, escape_char) ? 1 : 0; \
300 #undef STR_LIKE_NULLABLE
303 const int32_t lhs_len,
305 const int32_t rhs_len) {
310 const int32_t lhs_len,
312 const int32_t rhs_len) {
317 const int32_t lhs_len,
319 const int32_t rhs_len) {
324 const int32_t lhs_len,
326 const int32_t rhs_len) {
331 const int32_t lhs_len,
333 const int32_t rhs_len) {
338 const int32_t lhs_len,
340 const int32_t rhs_len) {
344 #define STR_CMP_NULLABLE(base_func) \
345 extern "C" RUNTIME_EXPORT DEVICE int8_t base_func##_nullable(const char* lhs, \
346 const int32_t lhs_len, \
348 const int32_t rhs_len, \
349 const int8_t bool_null) { \
350 if (!lhs || !rhs) { \
353 return base_func(lhs, lhs_len, rhs, rhs_len) ? 1 : 0; \
363 #undef STR_CMP_NULLABLE
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
RUNTIME_EXPORT DEVICE bool string_eq(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_gt(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_le(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_ge(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_lt(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
#define STR_LIKE_NULLABLE(base_func)
#define STR_LIKE_SIMPLE_NULLABLE(base_func)
static DEVICE LikeStatus string_like_match(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char, const bool is_ilike)
RUNTIME_EXPORT DEVICE bool string_like(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
static DEVICE int lowercase(char c)
RUNTIME_EXPORT DEVICE bool string_like_simple(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len)
Functions to support the LIKE and ILIKE operator in SQL. Only single-byte character set is supported ...
RUNTIME_EXPORT DEVICE bool string_ilike_simple(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len)
#define STR_CMP_NULLABLE(base_func)
RUNTIME_EXPORT DEVICE bool string_ne(const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
RUNTIME_EXPORT DEVICE bool string_ilike(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)