Skip to content

Commit

Permalink
AVRO-1545. Python. Fix to retain schema properties on primitive types…
Browse files Browse the repository at this point in the history
…. Contributed by Dustin Spicuzza.

git-svn-id: https://svn.apache.org/repos/asf/avro/trunk@1646362 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cutting committed Dec 17, 2014
1 parent 34174ef commit 7c0a16b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lang/py/src/avro/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,13 @@ def __eq__(self, that):
#
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

Expand Down Expand Up @@ -723,7 +723,7 @@ def make_avsc_object(json_data, names=None):
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)
Expand Down
4 changes: 4 additions & 0 deletions lang/py/test/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ def make_primitive_examples():
"symbols": [ "one", "two", "three" ],
"cp_float" : 1.0 }
""",True),
ExampleSchema("""\
{"type": "long",
"date": "true"}
""", True)
]

EXAMPLES = PRIMITIVE_EXAMPLES
Expand Down
6 changes: 3 additions & 3 deletions lang/py3/avro/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,15 @@ 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:
type: Type of the schema to construct. Must be primitive.
"""
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):
Expand Down Expand Up @@ -1153,7 +1153,7 @@ def _SchemaFromJSONObject(json_object, names):

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')
Expand Down
5 changes: 5 additions & 0 deletions lang/py3/avro/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ def MakePrimitiveExamples():
""",
valid=True,
),
ExampleSchema("""
{"type": "long", "date": "true"}
""",
valid=True,
),
]

EXAMPLES = PRIMITIVE_EXAMPLES
Expand Down

0 comments on commit 7c0a16b

Please sign in to comment.