Gawaboumga commented on code in PR #4057:
URL: https://github.com/apache/arrow-adbc/pull/4057#discussion_r2925949953
##########
c/driver/postgresql/copy/writer.h:
##########
@@ -735,6 +735,50 @@ class PostgresCopyTimestampFieldWriter : public
PostgresCopyFieldWriter {
}
};
+// Microseconds per day (24h)
+constexpr int64_t kUsecsPerDay = 86400LL * 1000000LL;
+
+template <enum ArrowTimeUnit TU>
+class PostgresCopyTimeFieldWriter : public PostgresCopyFieldWriter {
+ public:
+ ArrowErrorCode Write(ArrowBuffer* buffer, int64_t index, ArrowError* error)
override {
+ // PostgreSQL TIME binary format is an int64 microseconds-since-midnight
+ // and the COPY binary field length must be 8 bytes.
https://www.postgresql.org/docs/current/datatype-datetime.html
+ constexpr int32_t field_size_bytes = sizeof(int64_t);
+ NANOARROW_RETURN_NOT_OK(WriteChecked<int32_t>(buffer, field_size_bytes,
error));
+
+ const int64_t raw_value = ArrowArrayViewGetIntUnsafe(array_view_, index);
+ int64_t micros = 0;
+
+ switch (TU) {
+ case NANOARROW_TIME_UNIT_SECOND:
+ micros = raw_value * 1000000LL;
+ break;
+ case NANOARROW_TIME_UNIT_MILLI:
+ micros = raw_value * 1000LL;
+ break;
+ case NANOARROW_TIME_UNIT_MICRO:
+ micros = raw_value;
+ break;
+ case NANOARROW_TIME_UNIT_NANO:
+ micros = raw_value / 1000LL;
+ break;
+ }
+
+ if (micros < 0 || micros > kUsecsPerDay) {
Review Comment:
I reused the overflow validation logic of Duration or Timestamp
--
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]