Skip to content

Commit

Permalink
pg2arrow: put_decimal_value() handles numeric with negative weight in…
Browse files Browse the repository at this point in the history
…correctly.

issue #808
  • Loading branch information
kaigai committed Nov 11, 2024
1 parent 9035b71 commit da05771
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions arrow-tools/arrow_pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ static inline uint16_t __fetch_16bit(const void *addr)
#endif
}

static inline int16_t __fetch_16bit_signed(const void *addr)
{
#ifdef __PGSTROM_MODULE__
return *((int16_t *)addr);
#else
return (int16_t)be16toh(*((uint16_t *)addr));
#endif
}

static inline uint32_t __fetch_32bit(const void *addr)
{
#ifdef __PGSTROM_MODULE__
Expand Down Expand Up @@ -592,14 +601,13 @@ put_decimal_value(SQLfield *column, const char *addr, int sz)
NumericDigit digits[FLEXIBLE_ARRAY_MEMBER];
} *rawdata = (void *)addr;
nv.ndigits = __fetch_16bit(&rawdata->ndigits);
nv.weight = __fetch_16bit(&rawdata->weight);
nv.weight = __fetch_16bit_signed(&rawdata->weight);
nv.sign = __fetch_16bit(&rawdata->sign);
nv.dscale = __fetch_16bit(&rawdata->dscale);
nv.digits = rawdata->digits;
#endif /* __PGSTROM_MODULE__ */
if ((nv.sign & NUMERIC_SIGN_MASK) == NUMERIC_NAN)
Elog("Decimal128 cannot map NaN in PostgreSQL Numeric");

/* makes integer portion first */
for (d=0; d <= nv.weight; d++)
{
Expand Down

0 comments on commit da05771

Please sign in to comment.