You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Scott Reynolds (JIRA)" <ji...@apache.org> on 2014/05/23 23:11:01 UTC
[jira] [Created] (AVRO-1518) Python client support decimal.Decimal
types -> double encoding / decoding
Scott Reynolds created AVRO-1518:
------------------------------------
Summary: Python client support decimal.Decimal types -> double encoding / decoding
Key: AVRO-1518
URL: https://issues.apache.org/jira/browse/AVRO-1518
Project: Avro
Issue Type: Improvement
Reporter: Scott Reynolds
Python standard library > 2.4 provides a Decimal type that has much better semantics then standard binary float. Avro library should be able to accept Decimal's and encode them as doubles.
I also believe it should, by default, turn Avro double's into Decimal object instead of a float.
Simple patch allows for encoding a Decimal into an Avro double
{code}
--- io.py 2014-05-23 13:41:14.000000000 -0700
+++ /Users/sreynolds/Projects/avro-1.7.6 2/src/avro/io.py 2014-05-23 13:44:03.000000000 -0700
@@ -46,6 +46,11 @@ try:
except ImportError:
import simplejson as json
+try:
+ from decimal import Decimal
+except ImportError:
+ Decimal = float
+
#
# Constants
#
@@ -117,7 +122,7 @@ def validate(expected_schema, datum):
and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE)
elif schema_type in ['float', 'double']:
return (isinstance(datum, int) or isinstance(datum, long)
- or isinstance(datum, float))
+ or isinstance(datum, float) or instance(datum, Decimal))
elif schema_type == 'fixed':
return isinstance(datum, str) and len(datum) == expected_schema.size
elif schema_type == 'enum':
{code}
--
This message was sent by Atlassian JIRA
(v6.2#6252)