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

Function ToStringVal

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

Source from the content-addressed store, hash-verified

131typedef Writer<JsonUdfStrBuffer, UTF8<>, UTF8<>, JsonUdfAllocator> JsonUdfWriter;
132
133static StringVal ToStringVal(FunctionContext* ctx, const JsonUdfValue& values,
134 JsonUdfAllocator* allocator) {
135 DCHECK(values.IsArray());
136 if (values.Empty()) return StringVal::null();
137 JsonUdfStrBuffer sb(allocator);
138 JsonUdfWriter writer(sb, allocator);
139 JsonUdfValue res;
140 if (values.Size() == 1) {
141 const JsonUdfValue& v = values[0];
142 if (v.IsNull()) return StringVal::null();
143 if (v.IsString()) {
144 // RapidJSON will quote the strings. It's incompatible with Hive's behavior when
145 // the string is at the root, so we convert it ourselves here.
146 return StringVal::CopyFrom(ctx, reinterpret_cast<const uint8_t*>(v.GetString()),
147 v.GetStringLength());
148 }
149 RETURN_NULL_IF_OOM(v.Accept(writer));
150 } else { // multiple selected items, return an array string
151 RETURN_NULL_IF_OOM(values.Accept(writer));
152 }
153 const char* res_ptr = sb.GetString();
154 return StringVal::CopyFrom(ctx, reinterpret_cast<const uint8_t*>(res_ptr),
155 sb.GetSize());
156}
157
158// Extract all the values for 'key' where objects in 'queue' contain that key.
159// Replace the contents of queue with the values found.

Callers 2

GetJsonObjectImplMethod · 0.70
ToStringValMethod · 0.50

Calls 6

AcceptMethod · 0.80
GetSizeMethod · 0.80
EmptyMethod · 0.45
SizeMethod · 0.45
IsNullMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected