MCPcopy Create free account
hub / github.com/apache/arrow / Convert

Method Convert

cpp/src/arrow/json/converter.cc:238–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236 using PrimitiveConverter::PrimitiveConverter;
237
238 Status Convert(const std::shared_ptr<Array>& in, std::shared_ptr<Array>* out) override {
239 if (in->type_id() == Type::NA) {
240 return MakeArrayOfNull(out_type_, in->length(), pool_).Value(out);
241 }
242 const auto& dict_array = GetDictionaryArray(in);
243
244 using Builder = typename TypeTraits<T>::BuilderType;
245 Builder builder(out_type_, pool_);
246 RETURN_NOT_OK(builder.Resize(dict_array.indices()->length()));
247
248 // TODO(bkietz) this can be computed during parsing at low cost
249 int64_t data_length = 0;
250 auto visit_lengths_valid = [&](string_view value) {
251 data_length += value.size();
252 return Status::OK();
253 };
254
255 auto visit_lengths_null = [&]() {
256 // no-op
257 return Status::OK();
258 };
259
260 RETURN_NOT_OK(
261 VisitDictionaryEntries(dict_array, visit_lengths_valid, visit_lengths_null));
262 RETURN_NOT_OK(builder.ReserveData(data_length));
263
264 auto visit_valid = [&](string_view value) {
265 builder.UnsafeAppend(value);
266 return Status::OK();
267 };
268
269 auto visit_null = [&]() {
270 builder.UnsafeAppendNull();
271 return Status::OK();
272 };
273
274 RETURN_NOT_OK(VisitDictionaryEntries(dict_array, visit_valid, visit_null));
275 return builder.Finish(out);
276 }
277};
278
279Status MakeConverter(const std::shared_ptr<DataType>& out_type, MemoryPool* pool,

Callers

nothing calls this directly

Calls 13

MakeArrayOfNullFunction · 0.85
VisitDictionaryEntriesFunction · 0.85
indicesMethod · 0.80
OKFunction · 0.70
type_idMethod · 0.45
ValueMethod · 0.45
lengthMethod · 0.45
ResizeMethod · 0.45
sizeMethod · 0.45
ReserveDataMethod · 0.45
UnsafeAppendMethod · 0.45
UnsafeAppendNullMethod · 0.45

Tested by

no test coverage detected