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

Method RegexpReplace

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

Source from the content-addressed store, hash-verified

1125}
1126
1127StringVal StringFunctions::RegexpReplace(FunctionContext* context, const StringVal& str,
1128 const StringVal& pattern, const StringVal& replace) {
1129 if (str.is_null || pattern.is_null || replace.is_null) return StringVal::null();
1130
1131 re2::RE2* re = reinterpret_cast<re2::RE2*>(
1132 context->GetFunctionState(FunctionContext::THREAD_LOCAL));
1133 scoped_ptr<re2::RE2> scoped_re; // destroys re if state->re is NULL
1134 if (re == NULL) {
1135 DCHECK(!context->IsArgConstant(1));
1136 string error_str;
1137 re = CompileRegex(pattern, &error_str, StringVal::null());
1138 if (re == NULL) {
1139 context->AddWarning(error_str.c_str());
1140 return StringVal::null();
1141 }
1142 scoped_re.reset(re);
1143 }
1144
1145 re2::StringPiece replace_str =
1146 re2::StringPiece(reinterpret_cast<char*>(replace.ptr), replace.len);
1147 string result_str = AnyValUtil::ToString(str);
1148 re2::RE2::GlobalReplace(&result_str, *re, replace_str);
1149 return AnyValUtil::FromString(context, result_str);
1150}
1151
1152void StringFunctions::RegexpMatchCountPrepare(FunctionContext* context,
1153 FunctionContext::FunctionStateScope scope) {

Callers

nothing calls this directly

Calls 8

CompileRegexFunction · 0.85
FromStringFunction · 0.85
GetFunctionStateMethod · 0.80
IsArgConstantMethod · 0.80
AddWarningMethod · 0.80
resetMethod · 0.65
StringPieceClass · 0.50
ToStringFunction · 0.50

Tested by

no test coverage detected