lib/avro/schema_compatibility.rb in avro-1.10.1 vs lib/avro/schema_compatibility.rb in avro-1.10.2

- old
+ new

@@ -13,10 +13,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. module Avro module SchemaCompatibility + INT_COERCIBLE_TYPES_SYM = [:long, :float, :double].freeze + LONG_COERCIBLE_TYPES_SYM = [:float, :double].freeze + # Perform a full, recursive check that a datum written using the writers_schema # can be read using the readers_schema. def self.can_read?(writers_schema, readers_schema) Checker.new.can_read?(writers_schema, readers_schema) end @@ -29,10 +32,13 @@ # Perform a basic check that a datum written with the writers_schema could # be read using the readers_schema. This check includes matching the types, # including schema promotion, and matching the full name (including aliases) for named types. def self.match_schemas(writers_schema, readers_schema) + # Bypass deeper checks if the schemas are the same Ruby objects + return true if writers_schema.equal?(readers_schema) + w_type = writers_schema.type_sym r_type = readers_schema.type_sym # This conditional is begging for some OO love. if w_type == :union || r_type == :union @@ -60,12 +66,12 @@ return match_schemas(writers_schema.items, readers_schema.items) end end # Handle schema promotion - if w_type == :int && [:long, :float, :double].include?(r_type) + if w_type == :int && INT_COERCIBLE_TYPES_SYM.include?(r_type) return true - elsif w_type == :long && [:float, :double].include?(r_type) + elsif w_type == :long && LONG_COERCIBLE_TYPES_SYM.include?(r_type) return true elsif w_type == :float && r_type == :double return true elsif w_type == :string && r_type == :bytes return true