pitrou commented on code in PR #51038:
URL: https://github.com/apache/arrow/pull/51038#discussion_r4131092928
##########
cpp/src/arrow/json/parser.cc:
##########
@@ -876,25 +961,56 @@ class HandlerBase : public BlockParser,
return Status::OK();
}
- Status StartArrayImpl() {
- constexpr auto kind = Kind::kArray;
- if (ARROW_PREDICT_FALSE(builder_.kind != kind)) {
+ Status ParseObjectField(std::string_view key, sj::value value) {
+ ARROW_ASSIGN_OR_RAISE(auto found, SetFieldBuilder(key));
+
+ if (found) {
+ return ParseValue(value);
+ }
+
+ return HandleUnexpectedField(key, value);
+ }
+
+ template <Kind::type kind>
+ Status AppendScalar(BuilderPtr builder, std::string_view scalar) {
+ if (ARROW_PREDICT_FALSE(builder.kind != kind)) {
return IllegallyChangedTo(kind);
}
- StartNested();
- // append to the list builder in EndArrayImpl
- builder_ = Cast<kind>(builder_)->value_builder();
+ auto index = static_cast<int32_t>(scalar_values_builder_.length());
+ auto value_length = static_cast<int32_t>(scalar.size());
+ RETURN_NOT_OK(Cast<kind>(builder)->Append(index, value_length));
+ RETURN_NOT_OK(scalar_values_builder_.Reserve(1));
+ scalar_values_builder_.UnsafeAppend(scalar);
return Status::OK();
}
- Status EndArrayImpl(rj::SizeType size) {
- EndNested();
- // append to list_builder here
- auto list_builder = Cast<Kind::kArray>(builder_);
- return list_builder->Append(size);
+ /// \brief helper for parsing object fields.
+ ///
+ /// Sets the field builder with the given name, or returns false if
+ /// there is no such field or the field was already specified.
+ Result<bool> SetFieldBuilder(std::string_view key) {
Review Comment:
I see that `SetFieldBuilder` is only called by `ParseObjectField`. Can we
fold it there? It will make reasoning about the various error cases more
easily, IMHO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]