This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new e6a3126  Prevent error checking compatibility of a record reading a 
union (#368)
e6a3126 is described below

commit e6a3126e6f23ddabf829e47efa27d4ec2f76f7e0
Author: Tim Perkins <[email protected]>
AuthorDate: Sun Nov 18 12:30:03 2018 -0500

    Prevent error checking compatibility of a record reading a union (#368)
---
 lang/ruby/lib/avro/schema_compatibility.rb  |  2 ++
 lang/ruby/test/test_schema_compatibility.rb | 16 ++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lang/ruby/lib/avro/schema_compatibility.rb 
b/lang/ruby/lib/avro/schema_compatibility.rb
index 1842b3e..37401fc 100644
--- a/lang/ruby/lib/avro/schema_compatibility.rb
+++ b/lang/ruby/lib/avro/schema_compatibility.rb
@@ -141,6 +141,8 @@ module Avro
       end
 
       def match_record_schemas(writers_schema, readers_schema)
+        return false if writers_schema.type_sym == :union
+
         writer_fields_hash = writers_schema.fields_hash
         readers_schema.fields.each do |field|
           if writer_fields_hash.key?(field.name)
diff --git a/lang/ruby/test/test_schema_compatibility.rb 
b/lang/ruby/test/test_schema_compatibility.rb
index 138c895..4ec60ef 100644
--- a/lang/ruby/test/test_schema_compatibility.rb
+++ b/lang/ruby/test/test_schema_compatibility.rb
@@ -75,7 +75,9 @@ class TestSchemaCompatibility < Test::Unit::TestCase
       long_list_record_schema, long_list_record_schema,
       long_list_record_schema, int_list_record_schema,
 
-      null_schema, null_schema
+      null_schema, null_schema,
+
+      nested_optional_record, nested_record
     ].each_slice(2) do |(reader, writer)|
       assert_true(can_read?(writer, reader), "expecting #{reader} to read 
#{writer}")
     end
@@ -130,7 +132,9 @@ class TestSchemaCompatibility < Test::Unit::TestCase
 
       int_list_record_schema, long_list_record_schema,
 
-      null_schema, int_schema
+      null_schema, int_schema,
+
+      nested_record, nested_optional_record
     ].each_slice(2) do |(reader, writer)|
       assert_false(can_read?(writer, reader), "expecting #{reader} not to read 
#{writer}")
     end
@@ -413,6 +417,14 @@ class TestSchemaCompatibility < Test::Unit::TestCase
     Avro::Schema.parse('{"type":"record", "name":"Record1", 
"fields":[{"name":"a", "type":"int", "default":0}, {"name":"b", "type":"int", 
"default":0}]}')
   end
 
+  def nested_record
+    
Avro::Schema.parse('{"type":"record","name":"parent","fields":[{"name":"attribute","type":{"type":"record","name":"child","fields":[{"name":"id","type":"string"}]}}]}')
+  end
+
+  def nested_optional_record
+    
Avro::Schema.parse('{"type":"record","name":"parent","fields":[{"name":"attribute","type":["null",{"type":"record","name":"child","fields":[{"name":"id","type":"string"}]}],"default":null}]}')
+  end
+
   def int_list_record_schema
     Avro::Schema.parse <<-SCHEMA
       {

Reply via email to