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

Method AppendValue

cpp/src/arrow/json/from_string.cc:856–894  ·  view source on GitHub ↗

Append a JSON value that must be a 2-long array, containing the type_id and value of the UnionArray's slot.

Source from the content-addressed store, hash-verified

854 // Append a JSON value that must be a 2-long array, containing the type_id
855 // and value of the UnionArray's slot.
856 Status AppendValue(sj::value& json_obj) override {
857 ARROW_ASSIGN_OR_RAISE(bool is_null, internal::IsJsonNull(json_obj));
858 if (is_null) {
859 return this->AppendNull();
860 }
861
862 ARROW_ASSIGN_OR_RAISE(auto array, internal::GetJsonAs<sj::array>(json_obj));
863
864 int8_t id = 0;
865 std::shared_ptr<JSONConverter> child_converter;
866
867 RETURN_NOT_OK(ProcessJsonArrayElements<2>(
868 array, "[type_id, value] pair",
869 {[this, &id, &child_converter](sj::value& id_elem) {
870 ARROW_ASSIGN_OR_RAISE(auto id_value, internal::GetJsonAs<int64_t>(id_elem));
871 id = static_cast<int8_t>(id_value);
872 auto child_num = type_id_to_child_num_[id];
873 if (child_num == -1) {
874 return Status::Invalid("type_id ", id, " not found in ", *type_);
875 }
876 child_converter = child_converters_[child_num];
877
878 if (mode_ == UnionMode::SPARSE) {
879 RETURN_NOT_OK(checked_cast<SparseUnionBuilder&>(*builder_).Append(id));
880 for (auto&& other_converter : child_converters_) {
881 if (other_converter != child_converter) {
882 RETURN_NOT_OK(other_converter->AppendNull());
883 }
884 }
885 } else {
886 RETURN_NOT_OK(checked_cast<DenseUnionBuilder&>(*builder_).Append(id));
887 }
888 return Status::OK();
889 },
890 [&child_converter](sj::value& value_elem) {
891 return child_converter->AppendValue(value_elem);
892 }}));
893 return Status::OK();
894 }
895
896 std::shared_ptr<ArrayBuilder> builder() override { return builder_; }
897

Callers

nothing calls this directly

Calls 5

OKFunction · 0.70
InvalidFunction · 0.50
AppendNullMethod · 0.45
AppendMethod · 0.45
AppendValueMethod · 0.45

Tested by

no test coverage detected