MCPcopy Create free account
hub / github.com/apache/impala / CompileRegex

Function CompileRegex

be/src/exprs/string-functions-ir.cc:977–1002  ·  view source on GitHub ↗

The caller owns the returned regex. Returns NULL if the pattern could not be compiled.

Source from the content-addressed store, hash-verified

975
976// The caller owns the returned regex. Returns NULL if the pattern could not be compiled.
977re2::RE2* CompileRegex(const StringVal& pattern, string* error_str,
978 const StringVal& match_parameter) {
979 DCHECK(error_str != NULL);
980 re2::StringPiece pattern_sp(reinterpret_cast<char*>(pattern.ptr), pattern.len);
981 re2::RE2::Options options;
982 // Disable error logging in case e.g. every row causes an error
983 options.set_log_errors(false);
984 // Return the leftmost longest match (rather than the first match).
985 options.set_longest_match(true);
986 // Set the maximum memory used by re2's regex engine for storage
987 StringFunctions::SetRE2MemOpt(&options);
988 if (!match_parameter.is_null &&
989 !StringFunctions::SetRE2Options(match_parameter, error_str, &options)) {
990 return NULL;
991 }
992 re2::RE2* re = new re2::RE2(pattern_sp, options);
993 if (!re->ok()) {
994 stringstream ss;
995 ss << "Could not compile regexp pattern: " << AnyValUtil::ToString(pattern) << endl
996 << "Error: " << re->error();
997 *error_str = ss.str();
998 delete re;
999 return NULL;
1000 }
1001 return re;
1002}
1003
1004// This function sets options in the RE2 library before pattern matching.
1005bool StringFunctions::SetRE2Options(const StringVal& match_parameter,

Callers 5

RegexpPrepareMethod · 0.85
RegexpExtractMethod · 0.85
RegexpReplaceMethod · 0.85
RegexpMatchCount4ArgsMethod · 0.85

Calls 4

ToStringFunction · 0.50
okMethod · 0.45
errorMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected