WillAyd commented on code in PR #1288:
URL: https://github.com/apache/arrow-adbc/pull/1288#discussion_r1391634763
##########
c/driver/postgresql/postgres_copy_reader.h:
##########
@@ -1217,6 +1217,77 @@ class PostgresCopyIntervalFieldWriter : public
PostgresCopyFieldWriter {
}
};
+
+// Inspiration for this taken from get_str_from_var in the pg source
+// src/backend/utils/adt/numeric.c
+class PostgresCopyNumericFieldWriter : public PostgresCopyFieldWriter {
+public:
+ ArrowErrorCode Write(ArrowBuffer* buffer, int64_t index, ArrowError* error)
override {
+ struct ArrowDecimal decimal;
+ // TODO: these need to be inferred from the schema not hard coded
+ constexpr int16_t precision = 19;
+ constexpr int16_t scale = 8;
+ ArrowDecimalInit(&decimal, 128, precision, scale);
+ ArrowArrayViewGetDecimalUnsafe(array_view_, index, &decimal);
+ constexpr uint16_t kNumericPos = 0x0000;
+ constexpr uint16_t kNumericNeg = 0x4000;
+ constexpr int64_t kNBase = 10000;
+ // Number of decimal digits per Postgres digit
+ constexpr int kDecDigits = 4;
+
+ // TODO: need some kind of bounds check on this
+ int64_t decimal_int = ArrowDecimalGetIntUnsafe(&decimal);
Review Comment:
I don't think this is ultimately correct. I think ideally we would just use
the bytes backing the Decimal object, but I haven't yet figured out how that
all gets managed when multiple words are required
--
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]