class Avro::SchemaCompatibility::Checker

Constants

SIMPLE_CHECKS

Attributes

recursion_set[R]

Public Class Methods

new() click to toggle source
   # File lib/avro/schema_compatibility.rb
80 def initialize
81   @recursion_set = Set.new
82 end

Public Instance Methods

can_read?(writers_schema, readers_schema) click to toggle source
   # File lib/avro/schema_compatibility.rb
84 def can_read?(writers_schema, readers_schema)
85   full_match_schemas(writers_schema, readers_schema)
86 end
mutual_read?(writers_schema, readers_schema) click to toggle source
   # File lib/avro/schema_compatibility.rb
88 def mutual_read?(writers_schema, readers_schema)
89   can_read?(writers_schema, readers_schema) && can_read?(readers_schema, writers_schema)
90 end

Private Instance Methods

full_match_schemas(writers_schema, readers_schema) click to toggle source
    # File lib/avro/schema_compatibility.rb
 94 def full_match_schemas(writers_schema, readers_schema)
 95   return true if recursion_in_progress?(writers_schema, readers_schema)
 96 
 97   return false unless Avro::SchemaCompatibility.match_schemas(writers_schema, readers_schema)
 98 
 99   if writers_schema.type_sym != :union && SIMPLE_CHECKS.include?(readers_schema.type_sym)
100     return true
101   end
102 
103   case readers_schema.type_sym
104   when :record
105     match_record_schemas(writers_schema, readers_schema)
106   when :map
107     full_match_schemas(writers_schema.values, readers_schema.values)
108   when :array
109     full_match_schemas(writers_schema.items, readers_schema.items)
110   when :union
111     match_union_schemas(writers_schema, readers_schema)
112   when :enum
113     # reader's symbols must contain all writer's symbols
114     (writers_schema.symbols - readers_schema.symbols).empty?
115   else
116     if writers_schema.type_sym == :union && writers_schema.schemas.size == 1
117       full_match_schemas(writers_schema.schemas.first, readers_schema)
118     else
119       false
120     end
121   end
122 end
match_record_schemas(writers_schema, readers_schema) click to toggle source
    # File lib/avro/schema_compatibility.rb
135 def match_record_schemas(writers_schema, readers_schema)
136   writer_fields_hash = writers_schema.fields_hash
137   readers_schema.fields.each do |field|
138     if writer_fields_hash.key?(field.name)
139       return false unless full_match_schemas(writer_fields_hash[field.name].type, field.type)
140     else
141       return false unless field.default?
142     end
143   end
144 
145   return true
146 end
match_union_schemas(writers_schema, readers_schema) click to toggle source
    # File lib/avro/schema_compatibility.rb
124 def match_union_schemas(writers_schema, readers_schema)
125   raise 'readers_schema must be a union' unless readers_schema.type_sym == :union
126 
127   case writers_schema.type_sym
128   when :union
129     writers_schema.schemas.all? { |writer_type| full_match_schemas(writer_type, readers_schema) }
130   else
131     readers_schema.schemas.any? { |reader_type| full_match_schemas(writers_schema, reader_type) }
132   end
133 end
recursion_in_progress?(writers_schema, readers_schema) click to toggle source
    # File lib/avro/schema_compatibility.rb
148 def recursion_in_progress?(writers_schema, readers_schema)
149   key = [writers_schema.object_id, readers_schema.object_id]
150 
151   if recursion_set.include?(key)
152     true
153   else
154     recursion_set.add(key)
155     false
156   end
157 end