WillAyd commented on code in PR #712: URL: https://github.com/apache/arrow-adbc/pull/712#discussion_r1210992922
########## c/driver/postgresql/connection.cc: ########## @@ -310,6 +315,63 @@ class PqGetObjectsHelper { return ADBC_STATUS_OK; } + AdbcStatusCode AppendTables(std::string schema_name) { + struct StringBuilder query = {0}; + if (StringBuilderInit(&query, /*initial_size*/ 512)) { + return ADBC_STATUS_INTERNAL; + } + + std::vector<std::string> params = {schema_name}; + const char* stmt = + "SELECT c.relname, CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' " + "WHEN 'm' THEN 'materialized view' WHEN 't' THEN 'TOAST table' " + "WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' END " + "AS reltype FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace " + "WHERE c.relkind IN ('r','v','m','t','f','p') " + "AND pg_catalog.pg_table_is_visible(c.oid) AND n.nspname = $1"; + + if (StringBuilderAppend(&query, "%s", stmt)) { + StringBuilderReset(&query); + return ADBC_STATUS_INTERNAL; + } + + if (table_name_ != NULL) { + if (StringBuilderAppend(&query, "%s", " AND c.relname LIKE $2")) { + StringBuilderReset(&query); + return ADBC_STATUS_INTERNAL; + } + + params.push_back(std::string(table_name_)); + } + + auto result_helper = PqResultHelper{conn_, query.buffer, params, error_}; + + RAISE_ADBC(result_helper.Prepare()); + RAISE_ADBC(result_helper.Execute()); + for (PqResultRow row : result_helper) { + const char* table_name = row[0].data; + const char* table_type = row[1].data; + + if (depth_ > ADBC_OBJECT_DEPTH_TABLES) { + return ADBC_STATUS_NOT_IMPLEMENTED; + } else { + CHECK_NA(INTERNAL, + ArrowArrayAppendString(table_name_col_, ArrowCharView(table_name)), + error_); + CHECK_NA(INTERNAL, + ArrowArrayAppendString(table_type_col_, ArrowCharView(table_type)), + error_); + CHECK_NA(INTERNAL, ArrowArrayAppendNull(table_columns_col_, 1), error_); Review Comment: Ignore this comment - I think ok at the current depth to be null -- 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