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

Method AppendValue

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

Append a JSON value that is either an array of N elements in order or an object mapping struct names to values (omitted struct members are mapped to null).

Source from the content-addressed store, hash-verified

719 // or an object mapping struct names to values (omitted struct members
720 // are mapped to null).
721 Status AppendValue(const rj::Value& json_obj) override {
722 if (json_obj.IsNull()) {
723 return this->AppendNull();
724 }
725 if (json_obj.IsArray()) {
726 auto size = json_obj.Size();
727 auto expected_size = static_cast<uint32_t>(type_->num_fields());
728 if (size != expected_size) {
729 return Status::Invalid("Expected array of size ", expected_size,
730 ", got array of size ", size);
731 }
732 for (uint32_t i = 0; i < size; ++i) {
733 RETURN_NOT_OK(child_converters_[i]->AppendValue(json_obj[i]));
734 }
735 return builder_->Append();
736 }
737 if (json_obj.IsObject()) {
738 auto remaining = json_obj.MemberCount();
739 auto num_children = type_->num_fields();
740 for (int32_t i = 0; i < num_children; ++i) {
741 const auto& field = type_->field(i);
742 auto it = json_obj.FindMember(field->name());
743 if (it != json_obj.MemberEnd()) {
744 --remaining;
745 RETURN_NOT_OK(child_converters_[i]->AppendValue(it->value));
746 } else {
747 RETURN_NOT_OK(child_converters_[i]->AppendNull());
748 }
749 }
750 if (remaining > 0) {
751 rj::StringBuffer sb;
752 rj::Writer<rj::StringBuffer> writer(sb);
753 json_obj.Accept(writer);
754 return Status::Invalid("Unexpected members in JSON object for type ",
755 type_->ToString(), " Object: ", sb.GetString());
756 }
757 return builder_->Append();
758 }
759 return JSONTypeError("array or object", json_obj.GetType());
760 }
761
762 std::shared_ptr<ArrayBuilder> builder() override { return builder_; }
763

Callers

nothing calls this directly

Calls 14

JSONTypeErrorFunction · 0.85
InvalidFunction · 0.50
IsNullMethod · 0.45
AppendNullMethod · 0.45
SizeMethod · 0.45
num_fieldsMethod · 0.45
AppendValueMethod · 0.45
AppendMethod · 0.45
fieldMethod · 0.45
nameMethod · 0.45
AcceptMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected