class Avro::Schema::BytesSchema

Constants

ERROR_INVALID_PRECISION
ERROR_INVALID_SCALE
ERROR_PRECISION_TOO_SMALL

Attributes

precision[R]
scale[R]

Public Class Methods

new(type, logical_type=nil, precision=nil, scale=nil) click to toggle source
Calls superclass method Avro::Schema::PrimitiveSchema::new
    # File lib/avro/schema.rb
493 def initialize(type, logical_type=nil, precision=nil, scale=nil)
494   super(type.to_sym, logical_type)
495 
496   @precision = precision.to_i if precision
497   @scale = scale.to_i if scale
498 
499   validate_decimal! if logical_type == DECIMAL_LOGICAL_TYPE
500 end

Public Instance Methods

match_schema?(schema) click to toggle source
    # File lib/avro/schema.rb
511 def match_schema?(schema)
512   return true if super
513 
514   if logical_type == DECIMAL_LOGICAL_TYPE && schema.logical_type == DECIMAL_LOGICAL_TYPE
515     return precision == schema.precision && (scale || 0) == (schema.scale || 0)
516   end
517 
518   false
519 end
to_avro(names=nil) click to toggle source
Calls superclass method Avro::Schema::PrimitiveSchema#to_avro
    # File lib/avro/schema.rb
502 def to_avro(names=nil)
503   avro = super
504   return avro if avro.is_a?(String)
505 
506   avro['precision'] = precision if precision
507   avro['scale'] = scale if scale
508   avro
509 end

Private Instance Methods

validate_decimal!() click to toggle source
    # File lib/avro/schema.rb
523 def validate_decimal!
524   raise Avro::SchemaParseError, ERROR_INVALID_PRECISION unless precision.to_i.positive?
525   raise Avro::SchemaParseError, ERROR_INVALID_SCALE if scale.to_i.negative?
526   raise Avro::SchemaParseError, ERROR_PRECISION_TOO_SMALL if precision < scale.to_i
527 end