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 494 def initialize(type, logical_type=nil, precision=nil, scale=nil) 495 super(type.to_sym, logical_type) 496 497 @precision = precision.to_i if precision 498 @scale = scale.to_i if scale 499 500 validate_decimal! if logical_type == DECIMAL_LOGICAL_TYPE 501 end
Public Instance Methods
match_schema?(schema)
click to toggle source
Calls superclass method
Avro::Schema::PrimitiveSchema#match_schema?
# File lib/avro/schema.rb 512 def match_schema?(schema) 513 return true if super 514 515 if logical_type == DECIMAL_LOGICAL_TYPE && schema.logical_type == DECIMAL_LOGICAL_TYPE 516 return precision == schema.precision && (scale || 0) == (schema.scale || 0) 517 end 518 519 false 520 end
to_avro(names=nil)
click to toggle source
Calls superclass method
Avro::Schema::PrimitiveSchema#to_avro
# File lib/avro/schema.rb 503 def to_avro(names=nil) 504 avro = super 505 return avro if avro.is_a?(String) 506 507 avro['precision'] = precision if precision 508 avro['scale'] = scale if scale 509 avro 510 end
Private Instance Methods
validate_decimal!()
click to toggle source
# File lib/avro/schema.rb 524 def validate_decimal! 525 raise Avro::SchemaParseError, ERROR_INVALID_PRECISION unless precision.to_i.positive? 526 raise Avro::SchemaParseError, ERROR_INVALID_SCALE if scale.to_i.negative? 527 raise Avro::SchemaParseError, ERROR_PRECISION_TOO_SMALL if precision < scale.to_i 528 end