bottledwater-pg icon indicating copy to clipboard operation
bottledwater-pg copied to clipboard

Support arbitrary-precision numbers

Open ept opened this issue 10 years ago • 4 comments

Support for Postgres arbitrary-precision numeric datatypes is currently broken in Bottled Water. Need to work out how to map it to Avro:

  • One option is to use the Avro "decimal" logical type, which uses a byte array as the underlying storage, and I believe it maps to a java.math.BigInteger in the Java implementation of Avro.
  • Or it could simply be an ascii string containing the decimal digits. (That would take 2.4 times as much space.)

ept avatar Apr 23 '15 12:04 ept

My vote is for the first option, because it provides for an exact mapping from Postgres NUMERIC(precision, scale) type in it's most general form.

a1exsh avatar May 08 '15 14:05 a1exsh

On a second thought it's not all that easy to convert numeric internal representation into 2's complement bytea, since there appears to be no core function that would do that.

Do you think it would be OK to just re-use the logicalType: "decimal" spec with type: "string"?

a1exsh avatar May 08 '15 16:05 a1exsh

(replying to myself)

Actually, I've later found out that Avro spec defines logicalType: "decimal", type: "fixed", but doesn't seem to be supported by current C lib implementation.

a1exsh avatar May 22 '15 10:05 a1exsh

As of PR #114 (just merged) we now represent NUMERIC as a double. That's not ideal, as it could lose precision, therefore leaving this issue open; but it's better than just sending zero like we used to :)

samstokes avatar Sep 07 '16 21:09 samstokes