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

[GitHub] [arrow-adbc] paleolimbot commented on a diff in pull request #658: feat(c/driver/postgresql): Implement Postgres GetInfo

paleolimbot commented on code in PR #658:
URL: https://github.com/apache/arrow-adbc/pull/658#discussion_r1186871397


##########
c/driver/postgresql/postgresql_test.cc:
##########
@@ -97,6 +96,63 @@ class PostgresConnectionTest : public ::testing::Test,
  protected:
   PostgresQuirks quirks_;
 };
+
+TEST_F(PostgresConnectionTest, GetInfoMetadata) {
+  ASSERT_THAT(AdbcConnectionNew(&connection, &error), IsOkStatus(&error));
+  ASSERT_THAT(AdbcConnectionInit(&connection, &database, &error), IsOkStatus(&error));
+
+  adbc_validation::StreamReader reader;
+  std::vector<uint32_t> info = {
+      ADBC_INFO_DRIVER_NAME,
+      ADBC_INFO_DRIVER_VERSION,
+      ADBC_INFO_VENDOR_NAME,
+      ADBC_INFO_VENDOR_VERSION,
+  };
+  ASSERT_THAT(AdbcConnectionGetInfo(&connection, info.data(), info.size(),
+                                    &reader.stream.value, &error),
+              IsOkStatus(&error));
+  ASSERT_NO_FATAL_FAILURE(reader.GetSchema());
+
+  std::vector<uint32_t> seen;
+  while (true) {
+    ASSERT_NO_FATAL_FAILURE(reader.Next());
+    if (!reader.array->release) break;
+
+    for (int64_t row = 0; row < reader.array->length; row++) {
+      ASSERT_FALSE(ArrowArrayViewIsNull(reader.array_view->children[0], row));
+      const uint32_t code =
+          reader.array_view->children[0]->buffer_views[1].data.as_uint32[row];
+      seen.push_back(code);
+
+      switch (code) {
+        case ADBC_INFO_DRIVER_NAME: {
+          const char* expected = "ADBC PostgreSQL Driver";

Review Comment:
   If I were writing this test, I would probably start with `reader.array_view->children[1]->children[0]->buffer_views[2].data.as_char, len);` too. The downside of that is that it will crash instead of give a nice error if it's not true and that it's not too readable. Maybe:
   
   ```
   int child_index = 1; // Always true?
   struct ArrowArrayView* child = array_view.children[child_index];
   ArrowStringView val = ArrowArrayViewGetStringUnsafe(child, 0);
   EXPECT_EQ("ADBC PostgreSQL Driver", std::string(val.data, val.size_bytes));"
   ```
   
   is somewhere in between?



-- 
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