class Avro::Schema::Field
Attributes
aliases[R]
default[R]
doc[R]
name[R]
order[R]
type[R]
Public Class Methods
new(type, name, default=:no_default, order=nil, names=nil, namespace=nil, doc=nil, aliases=nil)
click to toggle source
# File lib/avro/schema.rb 568 def initialize(type, name, default=:no_default, order=nil, names=nil, namespace=nil, doc=nil, aliases=nil) # rubocop:disable Lint/MissingSuper 569 @type = subparse(type, names, namespace) 570 @name = name 571 @default = default 572 @order = order 573 @doc = doc 574 @aliases = aliases 575 @type_adapter = nil 576 validate_aliases! if aliases 577 validate_default! if default? && !Avro.disable_field_default_validation 578 end
Public Instance Methods
alias_names()
click to toggle source
# File lib/avro/schema.rb 592 def alias_names 593 @alias_names ||= Array(aliases) 594 end
default?()
click to toggle source
# File lib/avro/schema.rb 580 def default? 581 @default != :no_default 582 end
to_avro(names=Set.new)
click to toggle source
# File lib/avro/schema.rb 584 def to_avro(names=Set.new) 585 {'name' => name, 'type' => type.to_avro(names)}.tap do |avro| 586 avro['default'] = default if default? 587 avro['order'] = order if order 588 avro['doc'] = doc if doc 589 end 590 end
Private Instance Methods
validate_default!()
click to toggle source
# File lib/avro/schema.rb 598 def validate_default! 599 type_for_default = if type.type_sym == :union 600 type.schemas.first 601 else 602 type 603 end 604 case type_for_default.logical_type 605 when DECIMAL_LOGICAL_TYPE 606 # https://avro.apache.org/docs/1.11.1/specification/#schema-record 607 # Default values for bytes and fixed fields are JSON strings, where Unicode code points 0-255 are mapped to unsigned 8-bit byte values 0-255 608 options = SchemaValidator::DEFAULT_VALIDATION_OPTIONS.dup 609 options[:encoded] = true 610 Avro::SchemaValidator.validate!(type_for_default, default, options) 611 else 612 Avro::SchemaValidator.validate!(type_for_default, default) 613 end 614 rescue Avro::SchemaValidator::ValidationError => e 615 raise Avro::SchemaParseError, "Error validating default for #{name}: #{e.message}" 616 end