lidavidm commented on code in PR #1288: URL: https://github.com/apache/arrow-adbc/pull/1288#discussion_r1391642255
########## 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: probably too small of an optimization to matter, but in principle you should be able to put an upper bound on the number of digits needed to represent an Arrow decimal, and then just stack-allocate? -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org