You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2014/12/18 00:07:02 UTC

svn commit: r1646362 - in /avro/trunk: CHANGES.txt lang/py/src/avro/schema.py lang/py/test/test_schema.py lang/py3/avro/schema.py lang/py3/avro/tests/test_schema.py

Author: cutting
Date: Wed Dec 17 23:07:02 2014
New Revision: 1646362

URL: http://svn.apache.org/r1646362
Log:
AVRO-1545. Python. Fix to retain schema properties on primitive types.  Contributed by Dustin Spicuzza.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/py/src/avro/schema.py
    avro/trunk/lang/py/test/test_schema.py
    avro/trunk/lang/py3/avro/schema.py
    avro/trunk/lang/py3/avro/tests/test_schema.py

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1646362&r1=1646361&r2=1646362&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Dec 17 23:07:02 2014
@@ -96,6 +96,9 @@ Trunk (not yet released)
     AVRO-1604. Java: Fix ReflectData.AllowNull to work with @Nullable
     annotations. (Ryan Blue via cutting)
 
+    AVRO-1545. Python. Fix to retain schema properties on primitive types.
+    (Dustin Spicuzza via cutting)
+
 Avro 1.7.7 (23 July 2014)
 
   NEW FEATURES

Modified: avro/trunk/lang/py/src/avro/schema.py
URL: http://svn.apache.org/viewvc/avro/trunk/lang/py/src/avro/schema.py?rev=1646362&r1=1646361&r2=1646362&view=diff
==============================================================================
--- avro/trunk/lang/py/src/avro/schema.py (original)
+++ avro/trunk/lang/py/src/avro/schema.py Wed Dec 17 23:07:02 2014
@@ -385,13 +385,13 @@ class Field(object):
 #
 class PrimitiveSchema(Schema):
   """Valid primitive types are in PRIMITIVE_TYPES."""
-  def __init__(self, type):
+  def __init__(self, type, other_props=None):
     # Ensure valid ctor args
     if type not in PRIMITIVE_TYPES:
       raise AvroException("%s is not a valid primitive type." % type)
 
     # Call parent ctor
-    Schema.__init__(self, type)
+    Schema.__init__(self, type, other_props=other_props)
 
     self.fullname = type
 
@@ -723,7 +723,7 @@ def make_avsc_object(json_data, names=No
     type = json_data.get('type')
     other_props = get_other_props(json_data, SCHEMA_RESERVED_PROPS)
     if type in PRIMITIVE_TYPES:
-      return PrimitiveSchema(type)
+      return PrimitiveSchema(type, other_props)
     elif type in NAMED_TYPES:
       name = json_data.get('name')
       namespace = json_data.get('namespace', names.default_namespace)

Modified: avro/trunk/lang/py/test/test_schema.py
URL: http://svn.apache.org/viewvc/avro/trunk/lang/py/test/test_schema.py?rev=1646362&r1=1646361&r2=1646362&view=diff
==============================================================================
--- avro/trunk/lang/py/test/test_schema.py (original)
+++ avro/trunk/lang/py/test/test_schema.py Wed Dec 17 23:07:02 2014
@@ -289,6 +289,10 @@ OTHER_PROP_EXAMPLES = [
      "symbols": [ "one", "two", "three" ],
      "cp_float" : 1.0 }
     """,True),
+  ExampleSchema("""\
+    {"type": "long",
+     "date": "true"}
+    """, True)
 ]
 
 EXAMPLES = PRIMITIVE_EXAMPLES

Modified: avro/trunk/lang/py3/avro/schema.py
URL: http://svn.apache.org/viewvc/avro/trunk/lang/py3/avro/schema.py?rev=1646362&r1=1646361&r2=1646362&view=diff
==============================================================================
--- avro/trunk/lang/py3/avro/schema.py (original)
+++ avro/trunk/lang/py3/avro/schema.py Wed Dec 17 23:07:02 2014
@@ -643,7 +643,7 @@ class PrimitiveSchema(Schema):
   Valid primitive types are defined in PRIMITIVE_TYPES.
   """
 
-  def __init__(self, type):
+  def __init__(self, type, other_props=None):
     """Initializes a new schema object for the specified primitive type.
 
     Args:
@@ -651,7 +651,7 @@ class PrimitiveSchema(Schema):
     """
     if type not in PRIMITIVE_TYPES:
       raise AvroException('%r is not a valid primitive type.' % type)
-    super(PrimitiveSchema, self).__init__(type)
+    super(PrimitiveSchema, self).__init__(type, other_props=other_props)
 
   @property
   def name(self):
@@ -1153,7 +1153,7 @@ def _SchemaFromJSONObject(json_object, n
 
   if type in PRIMITIVE_TYPES:
     # FIXME should not ignore other properties
-    return PrimitiveSchema(type)
+    return PrimitiveSchema(type, other_props=other_props)
 
   elif type in NAMED_TYPES:
     name = json_object.get('name')

Modified: avro/trunk/lang/py3/avro/tests/test_schema.py
URL: http://svn.apache.org/viewvc/avro/trunk/lang/py3/avro/tests/test_schema.py?rev=1646362&r1=1646361&r2=1646362&view=diff
==============================================================================
--- avro/trunk/lang/py3/avro/tests/test_schema.py (original)
+++ avro/trunk/lang/py3/avro/tests/test_schema.py Wed Dec 17 23:07:02 2014
@@ -426,6 +426,11 @@ OTHER_PROP_EXAMPLES = [
     """,
     valid=True,
   ),
+  ExampleSchema("""
+    {"type": "long", "date": "true"}
+    """,
+    valid=True,
+  ),
 ]
 
 EXAMPLES = PRIMITIVE_EXAMPLES