You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "WillAyd (via GitHub)" <gi...@apache.org> on 2023/05/30 20:27:00 UTC

[GitHub] [arrow-adbc] WillAyd commented on a diff in pull request #712: feat(c/driver/postgresql): Implement GetObjects for tables

WillAyd commented on code in PR #712:
URL: https://github.com/apache/arrow-adbc/pull/712#discussion_r1210789680


##########
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:
   I _think_ there is some inconsistency with how we handle the parent->child relationships. From the schema->table we populate an empty list, but from table->constraints and table->columns we append 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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org