class BqGuess::Schema
Public Instance Methods
as_schema()
click to toggle source
# File lib/bq_guess/schema.rb, line 7 def as_schema values.map(&:as_schema) end
merge!(other)
click to toggle source
# File lib/bq_guess/schema.rb, line 11 def merge!(other) _merge!(other) set_nullable(other) end
null?(key)
click to toggle source
# File lib/bq_guess/schema.rb, line 16 def null?(key) !key?(key) || self[key].is_a?(Fields::Null) end
nullable!()
click to toggle source
# File lib/bq_guess/schema.rb, line 20 def nullable! each_value(&:nullable!) end
repeated?(key)
click to toggle source
# File lib/bq_guess/schema.rb, line 24 def repeated?(key) !!self[key]&.repeated? end
to_a()
click to toggle source
# File lib/bq_guess/schema.rb, line 28 def to_a values.map(&:to_hash) end
Private Instance Methods
_merge!(other)
click to toggle source
# File lib/bq_guess/schema.rb, line 34 def _merge!(other) each do |key, field| if other.null?(key) field.nullable! unless other.repeated?(key) else if field.is_a?(Fields::Null) self[key] = other[key] self[key].nullable! unless other.repeated?(key) end if field.is_a?(Fields::Record) && other[key].is_a?(Fields::Record) self[key].fields.merge!(other[key].fields) end end end end
set_nullable(other)
click to toggle source
# File lib/bq_guess/schema.rb, line 50 def set_nullable(other) (other.keys - keys).each do |key| self[key] = other[key] self[key].nullable! end end