kou commented on code in PR #15037: URL: https://github.com/apache/arrow/pull/15037#discussion_r1052621710
########## cpp/src/arrow/c/bridge.cc: ########## @@ -1777,17 +1779,30 @@ class ArrayStreamBatchReader : public RecordBatchReader { return Status::OK(); } - private: - std::shared_ptr<Schema> CacheSchema() const { - if (!schema_) { - struct ArrowSchema c_schema; - ARROW_CHECK_OK(StatusFromCError(stream_.get_schema(&stream_, &c_schema))); - schema_ = ImportSchema(&c_schema).ValueOrDie(); + static Result<std::shared_ptr<RecordBatchReader>> Make( + struct ArrowArrayStream* stream) { + if (ArrowArrayStreamIsReleased(stream)) { + return Status::Invalid("Cannot import released ArrowArrayStream"); + } + std::shared_ptr<Schema> schema; + struct ArrowSchema c_schema = {}; + Status status = StatusFromCError(stream, stream->get_schema(stream, &c_schema)); + if (status.ok()) { + status = ImportSchema(&c_schema).Value(&schema); } - return schema_; + if (!status.ok()) { + stream->release(stream); Review Comment: Should we use `ArrowArrayStreamRelease()` here? ```suggestion ArrowArrayStreamRelease(stream); ``` ########## cpp/src/arrow/c/bridge.cc: ########## @@ -1777,17 +1779,30 @@ class ArrayStreamBatchReader : public RecordBatchReader { return Status::OK(); } - private: - std::shared_ptr<Schema> CacheSchema() const { - if (!schema_) { - struct ArrowSchema c_schema; - ARROW_CHECK_OK(StatusFromCError(stream_.get_schema(&stream_, &c_schema))); - schema_ = ImportSchema(&c_schema).ValueOrDie(); + static Result<std::shared_ptr<RecordBatchReader>> Make( + struct ArrowArrayStream* stream) { + if (ArrowArrayStreamIsReleased(stream)) { + return Status::Invalid("Cannot import released ArrowArrayStream"); + } + std::shared_ptr<Schema> schema; + struct ArrowSchema c_schema = {}; + Status status = StatusFromCError(stream, stream->get_schema(stream, &c_schema)); Review Comment: ```suggestion auto status = StatusFromCError(stream, stream->get_schema(stream, &c_schema)); ``` -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org