lidavidm commented on code in PR #908:
URL: https://github.com/apache/arrow-adbc/pull/908#discussion_r1265609402


##########
c/driver/postgresql/postgres_copy_reader.h:
##########
@@ -212,7 +212,35 @@ class PostgresCopyNetworkEndianFieldReader : public 
PostgresCopyFieldReader {
   }
 };
 
-// Converts COPY resulting from the Postgres NUMERIC type into a string.
+// Reader for Intervals
+class PostgresCopyIntervalFieldReader : 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 != 128) {
+      ArrowErrorSet(error, "Expected field with %d bytes but found field with 
%d bytes",
+                    128,
+                    static_cast<int>(field_size_bytes));  // 
NOLINT(runtime/int)
+      return EINVAL;
+    }
+
+    // postgres stores time as usec, arrow stores as ns
+    const int64_t time = ReadUnsafe<int64_t>(data) * 1000;
+    const int32_t days = ReadUnsafe<int32_t>(data);
+    const int32_t months = ReadUnsafe<int32_t>(data);
+
+    NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(data_, &days, sizeof(int32_t)));
+    NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(data_, &months, 
sizeof(int32_t)));

Review Comment:
   I don't _think_ so, it's merely misleading.
   
   Unwrapping a bunch of layers of type references: 
https://github.com/apache/arrow/blob/fb7fb0db60aac7e48f6434b48aa23ada5c4885a2/cpp/src/arrow/type.h#L1529-L1536
   
   The code defines it as months-days-nanos, just hashes them in a different 
order for some reason (alphabetically?)



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