| 131 | typedef Writer<JsonUdfStrBuffer, UTF8<>, UTF8<>, JsonUdfAllocator> JsonUdfWriter; |
| 132 | |
| 133 | static 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. |