avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r897660 - in /hadoop/avro/trunk: CHANGES.txt src/py/avro/io.py src/test/py/test_io.py
Date Sun, 10 Jan 2010 17:09:45 GMT
Author: cutting
Date: Sun Jan 10 17:09:44 2010
New Revision: 897660

URL: http://svn.apache.org/viewvc?rev=897660&view=rev
Log:
AVRO-299.  Fix Python numeric promotion.  Contributed by Jeff Hammerbacher.

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/py/avro/io.py
    hadoop/avro/trunk/src/test/py/test_io.py

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=897660&r1=897659&r2=897660&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Sun Jan 10 17:09:44 2010
@@ -272,6 +272,8 @@
 
     AVRO-281. Symlink in build.xml does not work well with Cygwin (thiru)
 
+    AVRO-299. Fix Python numeric promotion.  (Jeff Hammerbacher via cutting)
+
 Avro 1.2.0 (14 October 2009)
 
   INCOMPATIBLE CHANGES

Modified: hadoop/avro/trunk/src/py/avro/io.py
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/py/avro/io.py?rev=897660&r1=897659&r2=897660&view=diff
==============================================================================
--- hadoop/avro/trunk/src/py/avro/io.py (original)
+++ hadoop/avro/trunk/src/py/avro/io.py Sun Jan 10 17:09:44 2010
@@ -93,7 +93,8 @@
     return ((isinstance(datum, int) or isinstance(datum, long)) 
             and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE)
   elif schema_type in ['float', 'double']:
-    return isinstance(datum, float)
+    return (isinstance(datum, int) or isinstance(datum, long)
+            or isinstance(datum, float))
   elif schema_type == 'fixed':
     return isinstance(datum, str) and len(datum) == expected_schema.size
   elif schema_type == 'enum':

Modified: hadoop/avro/trunk/src/test/py/test_io.py
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/py/test_io.py?rev=897660&r1=897659&r2=897660&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/py/test_io.py (original)
+++ hadoop/avro/trunk/src/test/py/test_io.py Sun Jan 10 17:09:44 2010
@@ -220,6 +220,24 @@
   # SCHEMA RESOLUTION
   #
 
+  def test_schema_promotion(self):
+    print_test_name('TEST SCHEMA PROMOTION')
+    # note that checking writers_schema.type in read_data
+    # allows us to handle promotion correctly
+    promotable_schemas = ['"int"', '"long"', '"float"', '"double"']
+    incorrect = 0
+    for i, ws in enumerate(promotable_schemas):
+      writers_schema = schema.parse(ws)
+      datum_to_write = 219
+      for rs in promotable_schemas[i + 1:]:
+        readers_schema = schema.parse(rs)
+        writer, enc, dw = write_datum(datum_to_write, writers_schema)
+        datum_read = read_datum(writer, writers_schema, readers_schema)
+        print 'Writer: %s Reader: %s' % (writers_schema, readers_schema)
+        print 'Datum Read: %s' % datum_read
+        if datum_read != datum_to_write: incorrect += 1
+    self.assertEquals(incorrect, 0)
+
   def test_unknown_symbol(self):
     print_test_name('TEST UNKNOWN SYMBOL')
     writers_schema = schema.parse("""\



Mime
View raw message