Class: Avro::Schema::PrimitiveSchema

Inherits:
Avro::Schema show all
Defined in:
lib/avro/schema.rb

Overview

Valid primitive types are in PRIMITIVE_TYPES.

Direct Known Subclasses

BytesSchema

Constant Summary

Constants inherited from Avro::Schema

CRC_EMPTY, DECIMAL_LOGICAL_TYPE, DEFAULT_VALIDATE_OPTIONS, INT_MAX_VALUE, INT_MIN_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE, NAMED_TYPES, NAMED_TYPES_SYM, NAME_REGEX, PRIMITIVE_TYPES, PRIMITIVE_TYPES_SYM, SINGLE_OBJECT_MAGIC_NUMBER, VALID_TYPES, VALID_TYPES_SYM

Instance Attribute Summary

Attributes inherited from Avro::Schema

#logical_type, #type_sym

Instance Method Summary collapse

Methods inherited from Avro::Schema

#==, #be_read?, #crc_64_avro_fingerprint, #hash, #initFPTable, #md5_fingerprint, #mutual_read?, parse, #read?, real_parse, #sha256_fingerprint, #single_object_encoding_header, #single_object_schema_fingerprint, #subparse, #to_s, #type, #type_adapter, validate

Constructor Details

#initialize(type, logical_type = nil) ⇒ PrimitiveSchema

Returns a new instance of PrimitiveSchema.



466
467
468
469
470
471
472
473
474
# File 'lib/avro/schema.rb', line 466

def initialize(type, logical_type=nil)
  if PRIMITIVE_TYPES_SYM.include?(type)
    super(type, logical_type)
  elsif PRIMITIVE_TYPES.include?(type)
    super(type.to_sym, logical_type)
  else
    raise AvroError.new("#{type} is not a valid primitive type.")
  end
end

Instance Method Details

#match_schema?(schema) ⇒ Boolean

Returns:

  • (Boolean)


481
482
483
484
# File 'lib/avro/schema.rb', line 481

def match_schema?(schema)
  return type_sym == schema.type_sym
  # TODO: eventually this could handle schema promotion for primitive schemas too
end

#to_avro(names = nil) ⇒ Object



476
477
478
479
# File 'lib/avro/schema.rb', line 476

def to_avro(names=nil)
  hsh = super
  hsh.size == 1 ? type : hsh
end