efegokdemir commented on code in PR #4878:
URL: https://github.com/apache/arrow-adbc/pull/4878#discussion_r4245198483
##########
c/driver/sqlite/statement_reader.c:
##########
@@ -953,27 +953,30 @@ AdbcStatusCode
InternalSqliteStatementReaderAppendDoubleToBinary(
struct ArrowBuffer* offsets, struct ArrowBuffer* binary, double value,
int32_t* offset, struct AdbcError* error) {
static const size_t kReserve = 64;
- size_t buffer_size = kReserve;
- CHECK_NA(INTERNAL, ArrowBufferReserve(binary, buffer_size), error);
+ CHECK_NA(INTERNAL, ArrowBufferReserve(binary, kReserve), error);
char* output = (char*)(binary->data + binary->size_bytes);
- int written = 0;
- while (1) {
- written = snprintf(output, buffer_size, "%e", value);
- if (written < 0) {
- InternalAdbcSetError(error, "Encoding error when upcasting double to
string");
- return ADBC_STATUS_INTERNAL;
- } else if (((size_t)written) >= buffer_size) {
- // Truncated, resize and try again
- // Check for overflow - presumably this can never happen...?
- if (UINT_MAX - buffer_size < buffer_size) {
- InternalAdbcSetError(error, "Overflow when upcasting double to
string");
- return ADBC_STATUS_INTERNAL;
- }
- CHECK_NA(INTERNAL, ArrowBufferReserve(binary, buffer_size), error);
- buffer_size += buffer_size;
- continue;
+ // Keep enough significant digits to round-trip the binary64 value. SQLite's
+ // printf precision can be capped by the linked SQLite build, so use libc for
+ // finite values and SQLite's formatter for its non-finite spellings.
+ int written;
+ if (isfinite(value)) {
+ written = snprintf(output, (int)kReserve, "%.17g", value);
+ if (written >= 0 && written < (int)kReserve - 2 && strchr(output, '.') ==
NULL) {
Review Comment:
Normalised the decimal separator before the integral-value handling and
added a decimal-comma locale regression test. The SQLite tests, clang-format
and diff check pass.
--
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]