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

Function ProcessNumberIndex

be/src/exprs/string-functions.cc:255–285  ·  view source on GitHub ↗

Process number in array selection. path_idx points at the start of the number in path_str. Return next unprocessed index in path_str. Return -1 for errors.

Source from the content-addressed store, hash-verified

253/// Process number in array selection. path_idx points at the start of the number in
254/// path_str. Return next unprocessed index in path_str. Return -1 for errors.
255static int ProcessNumberIndex(FunctionContext* ctx, const StringVal& path_str,
256 int path_idx, JsonUdfValue* queue, JsonUdfAllocator* allocator) {
257 const uint8_t* path = path_str.ptr;
258 const char* number_start = reinterpret_cast<const char*>(path + path_idx);
259 int i = path_idx;
260 while (i < path_str.len && path[i] != ']') ++i;
261 if (i == path_str.len) {
262 string msg = Substitute("Unclosed brackets in json path '$0'",
263 AnyValUtil::ToString(path_str));
264 ctx->SetError(msg.c_str());
265 return -1;
266 }
267 StringParser::ParseResult parse_res;
268 int index = StringParser::StringToInt<int>(number_start, i - path_idx, &parse_res);
269 if (parse_res != StringParser::PARSE_SUCCESS || index < 0) {
270 const char* failure;
271 if (parse_res == StringParser::PARSE_FAILURE) {
272 failure = "Failed to parse json path '$0': Expected number at position $1";
273 } else if (parse_res == StringParser::PARSE_OVERFLOW) {
274 failure = "Failed to parse json path '$0': Index too large at position $1";
275 } else {
276 DCHECK(parse_res == StringParser::PARSE_SUCCESS && index < 0);
277 failure = "Failed to parse json path '$0': Negative index at position $1";
278 }
279 string msg = Substitute(failure, AnyValUtil::ToString(path_str), path_idx);
280 ctx->SetError(msg.c_str());
281 return -1;
282 }
283 RETURN_IF_OOM(SelectByIndex(index, queue, allocator), -1);
284 return i + 1; // i points at ']'
285}
286
287/// Parse json_str into Document. Return false for errors.
288static bool ParseStringVal(FunctionContext* ctx, const StringVal& json_str,

Callers 1

GetJsonObjectImplMethod · 0.85

Calls 4

SubstituteFunction · 0.85
SelectByIndexFunction · 0.85
ToStringFunction · 0.50
SetErrorMethod · 0.45

Tested by

no test coverage detected