You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2023/06/27 22:13:24 UTC

[arrow-adbc] branch main updated: feat(c/driver/postgresql): Int8 support (#858)

This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 1465aba0 feat(c/driver/postgresql): Int8 support (#858)
1465aba0 is described below

commit 1465aba08064509e62c1eef88f6add1b024147e3
Author: William Ayd <wi...@icloud.com>
AuthorDate: Tue Jun 27 15:13:18 2023 -0700

    feat(c/driver/postgresql): Int8 support (#858)
---
 c/driver/postgresql/postgresql_test.cc | 10 +++++++++-
 c/driver/postgresql/statement.cc       |  9 +++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/c/driver/postgresql/postgresql_test.cc b/c/driver/postgresql/postgresql_test.cc
index 429d59dd..159d2ab5 100644
--- a/c/driver/postgresql/postgresql_test.cc
+++ b/c/driver/postgresql/postgresql_test.cc
@@ -85,6 +85,15 @@ class PostgresQuirks : public adbc_validation::DriverQuirks {
     return "$" + std::to_string(index + 1);
   }
 
+  ArrowType IngestSelectRoundTripType(ArrowType ingest_type) const override {
+    switch (ingest_type) {
+      case NANOARROW_TYPE_INT8:
+        return NANOARROW_TYPE_INT16;
+      default:
+        return ingest_type;
+    }
+  }
+
   std::optional<std::string> PrimaryKeyTableDdl(std::string_view name) const override {
     std::string ddl = "CREATE TABLE ";
     ddl += name;
@@ -549,7 +558,6 @@ class PostgresStatementTest : public ::testing::Test,
   void SetUp() override { ASSERT_NO_FATAL_FAILURE(SetUpTest()); }
   void TearDown() override { ASSERT_NO_FATAL_FAILURE(TearDownTest()); }
 
-  void TestSqlIngestInt8() { GTEST_SKIP() << "Not implemented"; }
   void TestSqlIngestUInt8() { GTEST_SKIP() << "Not implemented"; }
   void TestSqlIngestUInt16() { GTEST_SKIP() << "Not implemented"; }
   void TestSqlIngestUInt32() { GTEST_SKIP() << "Not implemented"; }
diff --git a/c/driver/postgresql/statement.cc b/c/driver/postgresql/statement.cc
index bacf99ac..30926b4f 100644
--- a/c/driver/postgresql/statement.cc
+++ b/c/driver/postgresql/statement.cc
@@ -187,6 +187,7 @@ struct BindStream {
     for (size_t i = 0; i < bind_schema_fields.size(); i++) {
       PostgresTypeId type_id;
       switch (bind_schema_fields[i].type) {
+        case ArrowType::NANOARROW_TYPE_INT8:
         case ArrowType::NANOARROW_TYPE_INT16:
           type_id = PostgresTypeId::kInt2;
           param_lengths[i] = 2;
@@ -290,6 +291,13 @@ struct BindStream {
             param_values[col] = param_values_buffer.data() + param_values_offsets[col];
           }
           switch (bind_schema_fields[col].type) {
+            case ArrowType::NANOARROW_TYPE_INT8: {
+              const int16_t val =
+                  array_view->children[col]->buffer_views[1].data.as_int8[row];
+              const uint16_t value = ToNetworkInt16(val);
+              std::memcpy(param_values[col], &value, sizeof(int16_t));
+              break;
+            }
             case ArrowType::NANOARROW_TYPE_INT16: {
               const uint16_t value = ToNetworkInt16(
                   array_view->children[col]->buffer_views[1].data.as_int16[row]);
@@ -575,6 +583,7 @@ AdbcStatusCode PostgresStatement::CreateBulkTable(
     if (i > 0) create += ", ";
     create += source_schema.children[i]->name;
     switch (source_schema_fields[i].type) {
+      case ArrowType::NANOARROW_TYPE_INT8:
       case ArrowType::NANOARROW_TYPE_INT16:
         create += " SMALLINT";
         break;