Reranko05 commented on code in PR #51038:
URL: https://github.com/apache/arrow/pull/51038#discussion_r4071914750
##########
cpp/src/arrow/json/parser.cc:
##########
@@ -644,90 +641,73 @@ class RawBuilderSet {
arenas_;
};
-/// Three implementations are provided for BlockParser, one for each
-/// UnexpectedFieldBehavior. However most of the logic is identical in each
-/// case, so the majority of the implementation is in this base class
-class HandlerBase : public BlockParser,
- public rj::BaseReaderHandler<rj::UTF8<>, HandlerBase> {
+/// Parser implementation for BlockParser.
+class ParseImpl : public BlockParser {
public:
- explicit HandlerBase(MemoryPool* pool)
+ explicit ParseImpl(MemoryPool* pool, UnexpectedFieldBehavior
unexpected_field_behavior)
: BlockParser(pool),
+ unexpected_field_behavior_(unexpected_field_behavior),
builder_set_(pool),
field_index_(-1),
scalar_values_builder_(pool) {}
- /// Retrieve a pointer to a builder from a BuilderPtr
template <Kind::type kind>
enable_if_t<kind != Kind::kNull, RawArrayBuilder<kind>*> Cast(BuilderPtr
builder) {
return builder_set_.Cast<kind>(builder);
}
- /// Accessor for a stored error Status
Status Error() { return status_; }
- /// \defgroup rapidjson-handler-interface functions expected by rj::Reader
- ///
- /// bool Key(const char* data, rj::SizeType size, ...) is omitted since
- /// the behavior varies greatly between UnexpectedFieldBehaviors
- ///
- /// @{
- bool Null() {
- status_ = builder_set_.AppendNull(builder_stack_.back(), field_index_,
builder_);
- return status_.ok();
+ Status Null() {
+ return builder_set_.AppendNull(builder_stack_.back(), field_index_,
builder_);
+ }
+
+ Status HandleUnexpectedField(std::string_view key, sj::value value) {
+ switch (unexpected_field_behavior_) {
+ case UnexpectedFieldBehavior::Error:
+ return ParseError("unexpected field");
+
+ case UnexpectedFieldBehavior::Ignore:
+ return internal::ConsumeJsonValue(value);
+
+ case UnexpectedFieldBehavior::InferType: {
+ auto struct_builder = Cast<Kind::kObject>(builder_stack_.back());
+ auto leading_nulls = static_cast<uint32_t>(struct_builder->length() -
1);
+
+ builder_ = BuilderPtr(Kind::kNull, leading_nulls, true);
Review Comment:
Addressed.
--
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]