Class: Avro::Schema::BytesSchema

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

Constant Summary collapse

ERROR_INVALID_SCALE =
'Scale must be greater than or equal to 0'
ERROR_INVALID_PRECISION =
'Precision must be positive'
ERROR_PRECISION_TOO_SMALL =
'Precision must be greater than scale'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, logical_type = nil, precision = nil, scale = nil) ⇒ BytesSchema

Returns a new instance of BytesSchema.



494
495
496
497
498
499
500
501
# File 'lib/avro/schema.rb', line 494

def initialize(type, logical_type=nil, precision=nil, scale=nil)
  super(type.to_sym, logical_type)

  @precision = precision.to_i if precision
  @scale = scale.to_i if scale

  validate_decimal! if logical_type == DECIMAL_LOGICAL_TYPE
end

Instance Attribute Details

#precisionObject (readonly)

Returns the value of attribute precision.



492
493
494
# File 'lib/avro/schema.rb', line 492

def precision
  @precision
end

#scaleObject (readonly)

Returns the value of attribute scale.



492
493
494
# File 'lib/avro/schema.rb', line 492

def scale
  @scale
end

Instance Method Details

#match_schema?(schema) ⇒ Boolean

Returns:

  • (Boolean)


512
513
514
515
516
517
518
519
520
# File 'lib/avro/schema.rb', line 512

def match_schema?(schema)
  return true if super

  if logical_type == DECIMAL_LOGICAL_TYPE && schema.logical_type == DECIMAL_LOGICAL_TYPE
    return precision == schema.precision && (scale || 0) == (schema.scale || 0)
  end

  false
end

#to_avro(names = nil) ⇒ Object



503
504
505
506
507
508
509
510
# File 'lib/avro/schema.rb', line 503

def to_avro(names=nil)
  avro = super
  return avro if avro.is_a?(String)

  avro['precision'] = precision if precision
  avro['scale'] = scale if scale
  avro
end