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


##########
c/driver/postgresql/postgres_copy_reader.h:
##########
@@ -212,6 +212,32 @@ class PostgresCopyNetworkEndianFieldReader : public 
PostgresCopyFieldReader {
   }
 };
 
+// Reader for Durations; Similar to PostgresCopyNetworkEndianFieldReader but
+// discards an extra 64 bits per read (representing the postgres day / month)
+class PostgresIntervalReader : public PostgresCopyFieldReader {
+ public:
+  ArrowErrorCode Read(ArrowBufferView* data, int32_t field_size_bytes, 
ArrowArray* array,
+                      ArrowError* error) override {
+    if (field_size_bytes <= 0) {
+      return ArrowArrayAppendNull(array, 1);
+    }
+
+    if (field_size_bytes != static_cast<int32_t>(sizeof(int64_t) * 2)) {
+      ArrowErrorSet(error, "Expected field with %d bytes but found field with 
%d bytes",
+                    static_cast<int>(sizeof(int64_t)),
+                    static_cast<int>(field_size_bytes));  // 
NOLINT(runtime/int)
+      return EINVAL;
+    }
+
+    int64_t value = ReadUnsafe<int64_t>(data);
+    NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(data_, &value, sizeof(int64_t)));
+
+    // discard unnecessary bits

Review Comment:
   On second though probably want to raise if these are non-zero



##########
c/driver/postgresql/postgres_copy_reader.h:
##########
@@ -212,6 +212,32 @@ class PostgresCopyNetworkEndianFieldReader : public 
PostgresCopyFieldReader {
   }
 };
 
+// Reader for Durations; Similar to PostgresCopyNetworkEndianFieldReader but
+// discards an extra 64 bits per read (representing the postgres day / month)
+class PostgresIntervalReader : public PostgresCopyFieldReader {
+ public:
+  ArrowErrorCode Read(ArrowBufferView* data, int32_t field_size_bytes, 
ArrowArray* array,
+                      ArrowError* error) override {
+    if (field_size_bytes <= 0) {
+      return ArrowArrayAppendNull(array, 1);
+    }
+
+    if (field_size_bytes != static_cast<int32_t>(sizeof(int64_t) * 2)) {
+      ArrowErrorSet(error, "Expected field with %d bytes but found field with 
%d bytes",
+                    static_cast<int>(sizeof(int64_t)),
+                    static_cast<int>(field_size_bytes));  // 
NOLINT(runtime/int)
+      return EINVAL;
+    }
+
+    int64_t value = ReadUnsafe<int64_t>(data);
+    NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(data_, &value, sizeof(int64_t)));
+
+    // discard unnecessary bits

Review Comment:
   On second thought probably want to raise if these are non-zero



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

Reply via email to