avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1006021 - in /avro/trunk: CHANGES.txt lang/py/src/avro/io.py lang/py/test/test_io.py
Date Fri, 08 Oct 2010 21:15:00 GMT
Author: cutting
Date: Fri Oct  8 21:14:58 2010
New Revision: 1006021

URL: http://svn.apache.org/viewvc?rev=1006021&view=rev
Log:
AVRO-537. Python: Remove unneeded schema validations.  Contributed by Erik Frey.

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

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1006021&r1=1006020&r2=1006021&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Oct  8 21:14:58 2010
@@ -21,6 +21,11 @@ Avro 1.4.1 (unreleased)
     AVRO-634. Java: Add support for reading Hadoop sequence files as
     Avro data to MapReduce API. (cutting)
 
+  OPTIMIZATIONS
+
+    AVRO-537. Python: Remove unneeded schema validations.
+    (Erik Frey via cutting)
+
   IMPROVEMENTS
 
     AVRO-655. Change build so that 'dist' target no longer also runs C

Modified: avro/trunk/lang/py/src/avro/io.py
URL: http://svn.apache.org/viewvc/avro/trunk/lang/py/src/avro/io.py?rev=1006021&r1=1006020&r2=1006021&view=diff
==============================================================================
--- avro/trunk/lang/py/src/avro/io.py (original)
+++ avro/trunk/lang/py/src/avro/io.py Fri Oct  8 21:14:58 2010
@@ -743,13 +743,13 @@ class DatumWriter(object):
                             set_writers_schema)
 
   def write(self, datum, encoder):
+    # validate datum
+    if not validate(self.writers_schema, datum):
+      raise AvroTypeException(self.writers_schema, datum)
+    
     self.write_data(self.writers_schema, datum, encoder)
 
   def write_data(self, writers_schema, datum, encoder):
-    # validate datum
-    if not validate(writers_schema, datum):
-      raise AvroTypeException(writers_schema, datum)
-    
     # function dispatch to write datum
     if writers_schema.type == 'null':
       encoder.write_null(datum)

Modified: avro/trunk/lang/py/test/test_io.py
URL: http://svn.apache.org/viewvc/avro/trunk/lang/py/test/test_io.py?rev=1006021&r1=1006020&r2=1006021&view=diff
==============================================================================
--- avro/trunk/lang/py/test/test_io.py (original)
+++ avro/trunk/lang/py/test/test_io.py Fri Oct  8 21:14:58 2010
@@ -324,5 +324,14 @@ class TestIO(unittest.TestCase):
     print 'Datum Read: %s' % datum_read
     self.assertEquals(datum_to_read, datum_read)
 
+  def test_type_exception(self):
+    print_test_name('TEST TYPE EXCEPTION')
+    writers_schema = schema.parse("""\
+      {"type": "record", "name": "Test",
+       "fields": [{"name": "F", "type": "int"},
+                  {"name": "E", "type": "int"}]}""")
+    datum_to_write = {'E': 5, 'F': 'Bad'}
+    self.assertRaises(io.AvroTypeException, write_datum, datum_to_write, writers_schema)
+
 if __name__ == '__main__':
   unittest.main()



Mime
View raw message