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


##########
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);
+    // TODO: is -INT64_MIN possible? If so how do we handle?
+    if (decimal_int < 0) {
+      decimal_int = -decimal_int;
+    }
+    std::vector<int16_t> pg_digits;

Review Comment:
   OK cool. Shouldn't be too hard to switch to that - just need to figure out 
how to handle once I get multi-word decimals supported



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