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

Method Substring

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

This behaves identically to the mysql implementation, namely: - 1-indexed positions - supported negative positions (count from the end of the string) - [optional] len. No len indicates longest substr possible Marks as IR_ALWAYS_INLINE since this is called in other overloads. So the overloads can also replace GetConstFnAttr() calls in codegen.

Source from the content-addressed store, hash-verified

60// Marks as IR_ALWAYS_INLINE since this is called in other overloads.
61// So the overloads can also replace GetConstFnAttr() calls in codegen.
62IR_ALWAYS_INLINE StringVal StringFunctions::Substring(FunctionContext* context,
63 const StringVal& str, const BigIntVal& pos, const BigIntVal& len) {
64 if (str.is_null || pos.is_null || len.is_null) return StringVal::null();
65 if (context->impl()->GetConstFnAttr(FunctionContextImpl::UTF8_MODE)) {
66 return Utf8Substring(context, str, pos, len);
67 }
68 int fixed_pos = pos.val;
69 if (fixed_pos < 0) fixed_pos = str.len + fixed_pos + 1;
70 int max_len = str.len - fixed_pos + 1;
71 int fixed_len = ::min(static_cast<int>(len.val), max_len);
72 if (fixed_pos > 0 && fixed_pos <= str.len && fixed_len > 0) {
73 return StringVal(str.ptr + fixed_pos - 1, fixed_len);
74 } else {
75 return StringVal();
76 }
77}
78
79StringVal StringFunctions::Substring(FunctionContext* context,
80 const StringVal& str, const BigIntVal& pos) {

Callers 4

ReplaceMethod · 0.45
InstrMethod · 0.45
ParseUrlMethod · 0.45
ParseUrlKeyMethod · 0.45

Calls 5

minFunction · 0.85
StringValClass · 0.85
BigIntValClass · 0.85
GetConstFnAttrMethod · 0.80
implMethod · 0.80

Tested by

no test coverage detected