lidavidm commented on code in PR #1184:
URL: https://github.com/apache/arrow-adbc/pull/1184#discussion_r1355008295
##########
c/driver/postgresql/postgres_copy_reader.h:
##########
@@ -1198,6 +1198,71 @@ class PostgresCopyDoubleFieldWriter : public
PostgresCopyFieldWriter {
}
};
+class PostgresCopyIntervalFieldWriter : public PostgresCopyFieldWriter {
+ public:
+ ArrowErrorCode Write(ArrowBuffer* buffer, int64_t index, ArrowError* error)
override {
+ constexpr int32_t field_size_bytes = 16;
+ NANOARROW_RETURN_NOT_OK(WriteChecked<int32_t>(buffer, field_size_bytes,
error));
+
+ struct ArrowInterval interval;
+ ArrowIntervalInit(&interval, NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO);
+ ArrowArrayViewGetIntervalUnsafe(array_view_, index, &interval);
+ const int64_t ms = interval.ns / 1000;
+ NANOARROW_RETURN_NOT_OK(WriteChecked<int64_t>(buffer, ms, error));
+ NANOARROW_RETURN_NOT_OK(WriteChecked<int32_t>(buffer, interval.days,
error));
+ NANOARROW_RETURN_NOT_OK(WriteChecked<int32_t>(buffer, interval.months,
error));
+
+ return ADBC_STATUS_OK;
+ }
+};
+
+template <enum ArrowTimeUnit TU>
+class PostgresCopyDurationFieldWriter : public PostgresCopyFieldWriter {
+ public:
+ ArrowErrorCode Write(ArrowBuffer* buffer, int64_t index, ArrowError* error)
override {
+ constexpr int32_t field_size_bytes = 16;
+ NANOARROW_RETURN_NOT_OK(WriteChecked<int32_t>(buffer, field_size_bytes,
error));
+
+ int64_t raw_value = ArrowArrayViewGetIntUnsafe(array_view_, index);
+ int64_t value;
+
+ bool overflow_safe = true;
+ switch (TU) {
+ case NANOARROW_TIME_UNIT_SECOND:
+ if ((overflow_safe = raw_value <= kMaxSafeSecondsToMicros &&
+ raw_value >= kMinSafeSecondsToMicros)) {
+ value = raw_value * 1000000;
+ }
+ break;
+ case NANOARROW_TIME_UNIT_MILLI:
+ if ((overflow_safe = raw_value <= kMaxSafeMillisToMicros &&
+ raw_value >= kMinSafeMillisToMicros)) {
+ value = raw_value * 1000;
+ }
+ break;
+ case NANOARROW_TIME_UNIT_MICRO:
+ value = raw_value;
+ break;
+ case NANOARROW_TIME_UNIT_NANO:
+ value = raw_value / 1000;
+ break;
+ }
+
+ if (!overflow_safe) {
+ return ADBC_STATUS_INVALID_ARGUMENT;
Review Comment:
Can we set the error message here?
--
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]