Reranko05 commented on code in PR #50937:
URL: https://github.com/apache/arrow/pull/50937#discussion_r3842544994
##########
cpp/src/arrow/integration/json_integration.cc:
##########
@@ -125,44 +127,48 @@ Status IntegrationJsonWriter::WriteRecordBatch(const
RecordBatch& batch) {
class IntegrationJsonReader::Impl {
public:
Impl(MemoryPool* pool, const std::shared_ptr<Buffer>& data)
- : pool_(pool), data_(data), record_batches_(nullptr) {}
+ : pool_(pool), data_(data) {}
Status ParseAndReadSchema() {
- doc_.Parse(reinterpret_cast<const rj::Document::Ch*>(data_->data()),
- static_cast<size_t>(data_->size()));
- if (doc_.HasParseError()) {
- return Status::IOError("JSON parsing failed");
- }
+ ARROW_ASSIGN_OR_RAISE(doc_,
+ internal::ResolveSimdjsonResult(
+ parser_.parse(reinterpret_cast<const
char*>(data_->data()),
+
static_cast<size_t>(data_->size())),
+ "Failed to parse JSON"));
ARROW_ASSIGN_OR_RAISE(schema_, json::ReadSchema(doc_, pool_,
&dictionary_memo_));
- auto it = std::as_const(doc_).FindMember("batches");
- RETURN_NOT_ARRAY("batches", it, doc_);
- record_batches_ = &it->value;
+ ARROW_ASSIGN_OR_RAISE(record_batches_,
+
internal::ResolveSimdjsonResult(doc_["batches"].get_array(),
+ "Failed to get
batches"));
return Status::OK();
}
Result<std::shared_ptr<RecordBatch>> ReadRecordBatch(int i) {
- if (i < 0 || i >= static_cast<int>(record_batches_->GetArray().Size())) {
+ if (i < 0 || i >= static_cast<int>(record_batches_.size())) {
return Status::IndexError("record batch index ", i, " out of bounds");
}
- return json::ReadRecordBatch(record_batches_->GetArray()[i], schema_,
- &dictionary_memo_, pool_);
+
+ ARROW_ASSIGN_OR_RAISE(auto batch,
+
internal::ResolveSimdjsonResult(record_batches_.at(i),
Review Comment:
I see. Since `ReadRecordBatch()` provides indexed access and may be called
repeatedly, would it make sense to iterate over r`ecord_batches_` once during
initialization and store the elements in a` std::vector<JsonValue>`? That would
make subsequent indexed access `O(1)` instead of traversing the simdjson array
each time. Would this approach be fine?
--
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]