WillAyd commented on code in PR #676:
URL: https://github.com/apache/arrow-adbc/pull/676#discussion_r1190350559
##########
c/driver/postgresql/connection.cc:
##########
@@ -145,6 +145,76 @@ AdbcStatusCode PostgresConnection::GetInfo(struct
AdbcConnection* connection,
return BatchToArrayStream(&array, &schema, out, error);
}
+AdbcStatusCode PostgresConnectionGetObjectsImpl(
+ PGconn* conn, int depth, const char* catalog, const char* db_schema,
+ const char* table_name, const char** table_types, const char* column_name,
+ struct ArrowSchema* schema, struct ArrowArray* array, struct AdbcError*
error) {
+ RAISE_ADBC(AdbcInitConnectionObjectsSchema(schema, error));
+
+ struct ArrowError na_error = {0};
+ CHECK_NA_DETAIL(INTERNAL, ArrowArrayInitFromSchema(array, schema,
&na_error), &na_error,
+ error);
+ CHECK_NA(INTERNAL, ArrowArrayStartAppending(array), error);
+
+ struct ArrowArray* catalog_name_col = array->children[0];
+ struct ArrowArray* catalog_db_schemas_col = array->children[1];
+
+ // TODO: support proper filters
+ if (!catalog) {
+ struct StringBuilder query = {0};
+ if (StringBuilderInit(&query, /*initial_size=*/256) != 0) return
ADBC_STATUS_INTERNAL;
+
+ if (StringBuilderAppend(&query, "%s", "SELECT datname FROM
pg_catalog.pg_database"))
+ return ADBC_STATUS_INTERNAL;
+
+ PqResultHelper result_helper = PqResultHelper{conn, query.buffer};
+ StringBuilderReset(&query);
+ pg_result* result = result_helper.Execute();
+
+ ExecStatusType pq_status = PQresultStatus(result);
+ if (pq_status == PGRES_TUPLES_OK) {
+ int num_rows = PQntuples(result);
+ array->length = num_rows - 1; // makes ArrowArrayFinishElement happy,
but why?
Review Comment:
Wasn't sure about this but took inspiration from a comment I saw by
@paleolimbot
https://github.com/apache/arrow-nanoarrow/issues/67#issuecomment-1324185749
Had to do the `-1` to get it to work with the validation checks in
`ArrowArrayFinishBuildingDefault`, but admittedly don't understand the why of
this
--
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]