OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringLike.h File Reference

Functions to support the LIKE and ILIKE operator in SQL. Only single-byte character set is supported for now. More...

#include "../Shared/funcannotations.h"
#include <cstdint>
+ Include dependency graph for StringLike.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

RUNTIME_EXPORT DEVICE bool string_like (const char *str, int str_len, const char *pattern, int pat_len, char escape_char)
 
RUNTIME_EXPORT DEVICE bool string_ilike (const char *str, int str_len, const char *pattern, int pat_len, char escape_char)
 
RUNTIME_EXPORT DEVICE bool string_like_simple (const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, char escape_char)
 
RUNTIME_EXPORT DEVICE bool string_ilike_simple (const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, char escape_char)
 
RUNTIME_EXPORT DEVICE bool string_lt (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_eq (const char *lhs, const int32_t lhs_len, const char *rhs, const int32_t rhs_len)
 
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_ge (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 int32_t StringCompare (const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
 

Detailed Description

Functions to support the LIKE and ILIKE operator in SQL. Only single-byte character set is supported for now.

Definition in file StringLike.h.

Function Documentation

RUNTIME_EXPORT DEVICE bool string_eq ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 336 of file StringLike.cpp.

References StringCompare().

Referenced by StringDictionary::getCompare().

339  {
340  return StringCompare(lhs, lhs_len, rhs, rhs_len) == 0;
341 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:272

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT DEVICE bool string_ge ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 329 of file StringLike.cpp.

References StringCompare().

332  {
333  return StringCompare(lhs, lhs_len, rhs, rhs_len) >= 0;
334 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:272

+ Here is the call graph for this function:

RUNTIME_EXPORT DEVICE bool string_gt ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 322 of file StringLike.cpp.

References StringCompare().

325  {
326  return StringCompare(lhs, lhs_len, rhs, rhs_len) > 0;
327 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:272

+ Here is the call graph for this function:

RUNTIME_EXPORT DEVICE bool string_ilike ( const char *  str,
int  str_len,
const char *  pattern,
int  pat_len,
char  escape_char 
)
RUNTIME_EXPORT DEVICE bool string_ilike_simple ( const char *  str,
const int32_t  str_len,
const char *  pattern,
const int32_t  pat_len,
char  escape_char 
)

Definition at line 61 of file StringLike.cpp.

References lowercase().

Referenced by StringDictionaryProxy::getLike(), and StringDictionary::getLikeImpl().

65  {
66  int i, j;
67  int search_len = str_len - pat_len + 1;
68  for (i = 0; i < search_len; ++i) {
69  for (j = 0; j < pat_len && pattern[j] == lowercase(str[j + i]); ++j) {
70  }
71  if (j >= pat_len) {
72  return true;
73  }
74  }
75  return false;
76 }
static DEVICE int lowercase(char c)
Definition: StringLike.cpp:34

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT DEVICE bool string_le ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 315 of file StringLike.cpp.

References StringCompare().

318  {
319  return StringCompare(lhs, lhs_len, rhs, rhs_len) <= 0;
320 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:272

+ Here is the call graph for this function:

RUNTIME_EXPORT DEVICE bool string_like ( const char *  str,
int  str_len,
const char *  pattern,
int  pat_len,
char  escape_char 
)
RUNTIME_EXPORT DEVICE bool string_like_simple ( const char *  str,
const int32_t  str_len,
const char *  pattern,
const int32_t  pat_len,
char  escape_char 
)

Definition at line 43 of file StringLike.cpp.

Referenced by StringDictionaryProxy::getLike(), and StringDictionary::getLikeImpl().

47  {
48  int i, j;
49  int search_len = str_len - pat_len + 1;
50  for (i = 0; i < search_len; ++i) {
51  for (j = 0; j < pat_len && pattern[j] == str[j + i]; ++j) {
52  }
53  if (j >= pat_len) {
54  return true;
55  }
56  }
57  return false;
58 }

+ Here is the caller graph for this function:

RUNTIME_EXPORT DEVICE bool string_lt ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 308 of file StringLike.cpp.

References StringCompare().

Referenced by StringDictionary::getCompare(), StringDictionary::mergeSortedCache(), and StringDictionary::sortCache().

311  {
312  return StringCompare(lhs, lhs_len, rhs, rhs_len) < 0;
313 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:272

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT DEVICE bool string_ne ( const char *  lhs,
const int32_t  lhs_len,
const char *  rhs,
const int32_t  rhs_len 
)

Definition at line 343 of file StringLike.cpp.

References StringCompare().

346  {
347  return StringCompare(lhs, lhs_len, rhs, rhs_len) != 0;
348 }
RUNTIME_EXPORT DEVICE int32_t StringCompare(const char *s1, const int32_t s1_len, const char *s2, const int32_t s2_len)
Definition: StringLike.cpp:272

+ Here is the call graph for this function:

RUNTIME_EXPORT DEVICE int32_t StringCompare ( const char *  s1,
const int32_t  s1_len,
const char *  s2,
const int32_t  s2_len 
)

Definition at line 272 of file StringLike.cpp.

Referenced by string_eq(), string_ge(), string_gt(), string_le(), string_lt(), and string_ne().

275  {
276  const char* s1_ = s1;
277  const char* s2_ = s2;
278 
279  while (s1_ < s1 + s1_len && s2_ < s2 + s2_len && *s1_ == *s2_) {
280  s1_++;
281  s2_++;
282  }
283 
284  unsigned char c1 = (s1_ < s1 + s1_len) ? (*(unsigned char*)s1_) : 0;
285  unsigned char c2 = (s2_ < s2 + s2_len) ? (*(unsigned char*)s2_) : 0;
286 
287  return c1 - c2;
288 }

+ Here is the caller graph for this function: