lib/avro/io.rb in avro-salsify-fork-1.9.0.2 vs lib/avro/io.rb in avro-salsify-fork-1.9.0.3.pre1

- old
+ new

@@ -219,50 +219,11 @@ end end class DatumReader def self.match_schemas(writers_schema, 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 - return true - end - - if w_type == r_type - return true if Schema::PRIMITIVE_TYPES_SYM.include?(r_type) - - case r_type - when :record - return writers_schema.fullname == readers_schema.fullname - when :error - return writers_schema.fullname == readers_schema.fullname - when :request - return true - when :fixed - return writers_schema.fullname == readers_schema.fullname && - writers_schema.size == readers_schema.size - when :enum - return writers_schema.fullname == readers_schema.fullname - when :map - return writers_schema.values.type == readers_schema.values.type - when :array - return writers_schema.items.type == readers_schema.items.type - end - end - - # Handle schema promotion - if w_type == :int && [:long, :float, :double].include?(r_type) - return true - elsif w_type == :long && [:float, :double].include?(r_type) - return true - elsif w_type == :float && r_type == :double - return true - end - - return false + Avro::SchemaCompatibility.match_schemas(writers_schema, readers_schema) end attr_accessor :writers_schema, :readers_schema def initialize(writers_schema=nil, readers_schema=nil) @@ -393,23 +354,27 @@ # fill in the default values if readers_fields_hash.size > read_record.size writers_fields_hash = writers_schema.fields_hash readers_fields_hash.each do |field_name, field| unless writers_fields_hash.has_key? field_name - if !field.default.nil? + if field.default? field_val = read_default_value(field.type, field.default) read_record[field.name] = field_val else - # FIXME(jmhodges) another 'unset' here + raise AvroError, "Missing data for #{field.type} with no default" end end end end read_record end def read_default_value(field_schema, default_value) + if default_value == :no_default + raise AvroError, "Missing data for #{field_schema} with no default" + end + # Basically a JSON Decoder? case field_schema.type_sym when :null return nil when :boolean