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

Method Repeat

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

Source from the content-addressed store, hash-verified

166}
167
168StringVal StringFunctions::Repeat(
169 FunctionContext* context, const StringVal& str, const BigIntVal& n) {
170 if (str.is_null || n.is_null) return StringVal::null();
171 if (str.len == 0 || n.val <= 0) return StringVal();
172 if (n.val > StringVal::MAX_LENGTH) {
173 context->SetError(Substitute(ERROR_CHARACTER_LIMIT_EXCEEDED,
174 "Number of repeats in repeat() call",
175 PrettyPrinter::Print(StringVal::MAX_LENGTH, TUnit::BYTES)).c_str());
176 return StringVal::null();
177 }
178 static_assert(numeric_limits<int64_t>::max() / numeric_limits<int>::max()
179 >= StringVal::MAX_LENGTH,
180 "multiplying StringVal::len with positive int fits in int64_t");
181 int64_t out_len = str.len * n.val;
182 if (out_len > StringVal::MAX_LENGTH) {
183 context->SetError(Substitute(ERROR_CHARACTER_LIMIT_EXCEEDED,
184 "repeat() result",
185 PrettyPrinter::Print(StringVal::MAX_LENGTH, TUnit::BYTES)).c_str());
186 return StringVal::null();
187 }
188 StringVal result(context, static_cast<int>(out_len));
189 if (UNLIKELY(result.is_null)) return StringVal::null();
190 uint8_t* ptr = result.ptr;
191 for (int64_t i = 0; i < n.val; ++i) {
192 memcpy(ptr, str.ptr, str.len);
193 ptr += str.len;
194 }
195 return result;
196}
197
198StringVal StringFunctions::Lpad(FunctionContext* context, const StringVal& str,
199 const BigIntVal& len, const StringVal& pad) {

Callers

nothing calls this directly

Calls 4

StringValClass · 0.85
SubstituteFunction · 0.85
maxFunction · 0.85
SetErrorMethod · 0.45

Tested by

no test coverage detected