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

Method AppendValue

cpp/src/arrow/json/from_string.cc:804–838  ·  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

802 // Append a JSON value that must be a 2-long array, containing the type_id
803 // and value of the UnionArray's slot.
804 Status AppendValue(const rj::Value& json_obj) override {
805 if (json_obj.IsNull()) {
806 return this->AppendNull();
807 }
808 if (!json_obj.IsArray()) {
809 return JSONTypeError("array", json_obj.GetType());
810 }
811 if (json_obj.Size() != 2) {
812 return Status::Invalid("Expected [type_id, value] pair, got array of size ",
813 json_obj.Size());
814 }
815 const auto& id_obj = json_obj[0];
816 if (!id_obj.IsInt()) {
817 return JSONTypeError("int", id_obj.GetType());
818 }
819
820 auto id = static_cast<int8_t>(id_obj.GetInt());
821 auto child_num = type_id_to_child_num_[id];
822 if (child_num == -1) {
823 return Status::Invalid("type_id ", id, " not found in ", *type_);
824 }
825
826 auto child_converter = child_converters_[child_num];
827 if (mode_ == UnionMode::SPARSE) {
828 RETURN_NOT_OK(checked_cast<SparseUnionBuilder&>(*builder_).Append(id));
829 for (auto&& other_converter : child_converters_) {
830 if (other_converter != child_converter) {
831 RETURN_NOT_OK(other_converter->AppendNull());
832 }
833 }
834 } else {
835 RETURN_NOT_OK(checked_cast<DenseUnionBuilder&>(*builder_).Append(id));
836 }
837 return child_converter->AppendValue(json_obj[1]);
838 }
839
840 std::shared_ptr<ArrayBuilder> builder() override { return builder_; }
841

Callers

nothing calls this directly

Calls 8

JSONTypeErrorFunction · 0.85
InvalidFunction · 0.50
IsNullMethod · 0.45
AppendNullMethod · 0.45
GetTypeMethod · 0.45
SizeMethod · 0.45
AppendMethod · 0.45
AppendValueMethod · 0.45

Tested by

no test coverage detected