class Fluent::BigQuery::RecordSchema
Constants
- FIELD_TYPES
Public Class Methods
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 224 def initialize(name, mode = :nullable) super(name, mode) @fields = {} end
Calls superclass method
Fluent::BigQuery::FieldSchema::new
Public Instance Methods
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 233 def [](name) @fields[name] end
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 237 def empty? @fields.empty? end
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 292 def format_one(record, is_load: false) out = {} record.each do |key, value| next if value.nil? schema = @fields[key] out[key] = schema ? schema.format(value, is_load: is_load) : value end out end
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 256 def load_schema(schema) schema.each do |field| raise ConfigError, 'field must have type' unless field.key?('type') name = field['name'] mode = (field['mode'] || 'nullable').downcase.to_sym type = field['type'].downcase.to_sym field_schema_class = FIELD_TYPES[type] raise ConfigError, "Invalid field type: #{field['type']}" unless field_schema_class field_schema = field_schema_class.new(name, mode) @fields[name] = field_schema if type == :record raise ConfigError, "record field must have fields" unless field.key?('fields') field_schema.load_schema(field['fields']) end end end
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 276 def register_field(name, type) if @fields.key?(name) and @fields[name].type != :timestamp raise ConfigError, "field #{name} is registered twice" end if name[/\./] recordname = $` fieldname = $' register_record_field(recordname) @fields[recordname].register_field(fieldname, type) else schema = FIELD_TYPES[type] raise ConfigError, "[Bug] Invalid field type #{type}" unless schema @fields[name] = schema.new(name) end end
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 241 def to_a @fields.map do |_, field_schema| field_schema.to_h end end
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 247 def to_h { :name => name, :type => type.to_s.upcase, :mode => mode.to_s.upcase, :fields => self.to_a, } end
Private Instance Methods
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 303 def register_record_field(name) if !@fields.key?(name) @fields[name] = RecordSchema.new(name) else unless @fields[name].kind_of?(RecordSchema) raise ConfigError, "field #{name} is required to be a record but already registered as #{@field[name]}" end end end