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

Function GetUtf8CodePointCount

be/src/exprs/mask-functions-ir.cc:195–211  ·  view source on GitHub ↗

Counting code points in the UTF-8 encoded string using the same method, 'to_unicode', as MaskSubStrUtf8 uses. So we can have a consistent behavior. Returns -1 if the string contains malformed(illegal/incomplete) code points.

Source from the content-addressed store, hash-verified

193/// as MaskSubStrUtf8 uses. So we can have a consistent behavior.
194/// Returns -1 if the string contains malformed(illegal/incomplete) code points.
195static int GetUtf8CodePointCount(FunctionContext* ctx, const StringVal& val) {
196 utf8_codecvt<char>::state_type cvt_state;
197 const char* p = reinterpret_cast<char*>(val.ptr);
198 const char* p_end = p + val.len;
199 int char_cnt = 0;
200 while (p != p_end) {
201 uint32_t c = utf8_codecvt<char>::to_unicode(cvt_state, p, p_end);
202 if (c == utf::illegal || c == utf::incomplete) {
203 ctx->SetError(Substitute("The $0-th code point $1 is $2",
204 char_cnt, AnyValUtil::ToString(val),
205 c == utf::illegal ? "illegal" : "incomplete").c_str());
206 return -1;
207 }
208 ++char_cnt;
209 }
210 return char_cnt;
211}
212
213/// Mask the given string except the first 'un_mask_char_count' chars. Ported from
214/// org.apache.hadoop.hive.ql.udf.generic.GenericUDFMaskShowFirstN.

Callers 2

MaskShowLastNImplFunction · 0.85
MaskLastNImplFunction · 0.85

Calls 3

SubstituteFunction · 0.85
ToStringFunction · 0.50
SetErrorMethod · 0.45

Tested by

no test coverage detected