@@ -750,37 +750,48 @@ class HandlerBase : public BlockParser {
750750 return Status::OK ();
751751 }
752752
753- simdjson::padded_string padded_json (reinterpret_cast <const char *>(json->data ()),
754- json->size ());
753+ auto parse = [&](const auto & input) -> Status {
754+ ARROW_ASSIGN_OR_RAISE (auto stream, arrow::internal::ResolveSimdjsonResult (
755+ parser_.iterate_many (input),
756+ " Failed to create JSON document stream" ));
757+
758+ for (auto document_result : stream) {
759+ ARROW_ASSIGN_OR_RAISE (
760+ auto document,
761+ arrow::internal::ResolveSimdjsonResult (
762+ document_result, " Failed to iterate JSON document stream" ));
763+
764+ if (num_rows_ == std::numeric_limits<int32_t >::max ()) {
765+ return Status::Invalid (" Row count overflowed int32_t" );
766+ }
755767
756- ARROW_ASSIGN_OR_RAISE (auto stream, arrow::internal::ResolveSimdjsonResult (
757- parser_.iterate_many (padded_json),
758- " Failed to create JSON document stream" ));
768+ ARROW_ASSIGN_OR_RAISE (
769+ auto value,
770+ arrow::internal::ResolveSimdjsonResult (
771+ document.get_value (), " JSON parse error: Failed to get JSON value" ));
759772
760- for (auto document_result : stream) {
761- ARROW_ASSIGN_OR_RAISE (
762- auto document, arrow::internal::ResolveSimdjsonResult (
763- document_result, " Failed to iterate JSON document stream" ));
773+ RETURN_NOT_OK (ParseValue (handler, value));
764774
765- if (num_rows_ == std::numeric_limits<int32_t >::max ()) {
766- return Status::Invalid (" Row count overflowed int32_t" );
775+ ++num_rows_;
767776 }
768777
769- ARROW_ASSIGN_OR_RAISE (
770- auto value,
771- arrow::internal::ResolveSimdjsonResult (
772- document.get_value (), " JSON parse error: Failed to get JSON value" ));
773-
774- RETURN_NOT_OK (ParseValue (handler, value));
778+ if (stream.truncated_bytes () != 0 ) {
779+ return ParseError (" The document is empty" );
780+ }
775781
776- ++num_rows_ ;
777- }
782+ return Status::OK () ;
783+ };
778784
779- if (stream.truncated_bytes () != 0 ) {
780- return ParseError (" The document is empty" );
785+ if (json->capacity () - json->size () >=
786+ static_cast <int64_t >(simdjson::SIMDJSON_PADDING )) {
787+ const auto padded_json = simdjson::padded_string_view (
788+ reinterpret_cast <const char *>(json->data ()), json->size (), json->capacity ());
789+ return parse (padded_json);
781790 }
782791
783- return Status::OK ();
792+ simdjson::padded_string padded_json (reinterpret_cast <const char *>(json->data ()),
793+ json->size ());
794+ return parse (padded_json);
784795 }
785796
786797 template <Kind::type kind>
0 commit comments