MCPcopy Create free account
hub / github.com/bytedance/bolt / nestedArrayVectorFromJson

Method nestedArrayVectorFromJson

bolt/vector/tests/utils/VectorMaker.h:642–674  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

640 /// string.
641 template <typename T>
642 ArrayVectorPtr nestedArrayVectorFromJson(
643 const std::vector<std::string>& jsonArrays,
644 const TypePtr& arrayType = ARRAY(CppToType<T>::create())) {
645 std::vector<std::optional<std::vector<std::optional<T>>>> baseVector;
646 std::vector<vector_size_t> offsets;
647 std::vector<vector_size_t> nulls;
648 const std::vector<std::optional<T>> empty;
649 int offset = 0;
650 for (auto i = 0; i < jsonArrays.size(); i++) {
651 const auto& jsonArray = jsonArrays.at(i);
652 BOLT_CHECK(!jsonArray.empty());
653 const folly::dynamic arraysObject = folly::parseJson(jsonArray);
654 offsets.push_back(offset);
655 if (arraysObject.isNull()) {
656 // Null array.
657 nulls.push_back(i);
658 continue;
659 }
660 for (const auto& nestedArray : arraysObject) {
661 if (nestedArray.isNull()) {
662 // Null nested array
663 baseVector.push_back(std::nullopt);
664 } else {
665 std::vector<std::optional<T>> elements;
666 appendElementsFromJsonArray(nestedArray, elements);
667 baseVector.push_back(elements);
668 }
669 }
670 offset += arraysObject.size();
671 }
672 auto baseArrayVector = arrayVectorNullable<T>(baseVector, arrayType);
673 return arrayVector(offsets, baseArrayVector, nulls);
674 }
675
676 ArrayVectorPtr allNullArrayVector(
677 vector_size_t size,

Callers

nothing calls this directly

Calls 7

ARRAYFunction · 0.85
createFunction · 0.50
sizeMethod · 0.45
atMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45
isNullMethod · 0.45

Tested by

no test coverage detected