WillAyd commented on code in PR #870:
URL: https://github.com/apache/arrow-adbc/pull/870#discussion_r1254893165
##########
c/driver/postgresql/statement.cc:
##########
@@ -438,91 +438,156 @@ int TupleReader::GetSchema(struct ArrowSchema* out) {
return na_res;
}
-int TupleReader::GetNext(struct ArrowArray* out) {
- if (!result_) {
- out->release = nullptr;
- return 0;
+int TupleReader::InitQueryAndFetchFirst(struct ArrowError* error) {
+ ResetQuery();
+
+ // Fetch + parse the header
+ int get_copy_res = PQgetCopyData(conn_, &pgbuf_, /*async=*/0);
+ data_.size_bytes = get_copy_res;
+ data_.data.as_char = pgbuf_;
+
+ if (get_copy_res == -2) {
+ StringBuilderAppend(&error_builder_, "[libpq] Fetch header failed: %s",
+ PQerrorMessage(conn_));
+ return EIO;
}
- // Clear the result, since the data is actually read from the connection
- PQclear(result_);
- result_ = nullptr;
+ int na_res = copy_reader_->ReadHeader(&data_, error);
+ if (na_res != NANOARROW_OK) {
+ StringBuilderAppend(&error_builder_, "[libpq] ReadHeader failed: %s",
error->message);
+ return EIO;
+ }
- // Clear the error builder
- error_builder_.size = 0;
+ return NANOARROW_OK;
+}
- struct ArrowError error;
- error.message[0] = '\0';
- struct ArrowBufferView data;
- data.data.data = nullptr;
- data.size_bytes = 0;
+int TupleReader::AppendRowAndFetchNext(struct ArrowError* error) {
+ // Parse the result (the header AND the first row are included in the first
+ // call to PQgetCopyData())
+ int na_res = copy_reader_->ReadRecord(&data_, error);
+ if (na_res != NANOARROW_OK && na_res != ENODATA) {
+ StringBuilderAppend(&error_builder_, "[libpq] ReadRecord failed at row
%ld: %s",
Review Comment:
Very minor but can avoid the cast here if you use the `PRId64` macro in the
format specifier
--
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]