Class: Fluent::BigQueryOutput::RecordSchema

Inherits:
FieldSchema
  • Object
show all
Defined in:
lib/fluent/plugin/out_bigquery.rb

Constant Summary collapse

FIELD_TYPES =
{
  :string => StringFieldSchema,
  :integer => IntegerFieldSchema,
  :float => FloatFieldSchema,
  :boolean => BooleanFieldSchema
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeRecordSchema

Returns a new instance of RecordSchema.



361
362
363
# File 'lib/fluent/plugin/out_bigquery.rb', line 361

def initialize
  @fields = {}
end

Instance Method Details

#[](name) ⇒ Object



369
370
371
# File 'lib/fluent/plugin/out_bigquery.rb', line 369

def [](name)
  @fields[name]
end

#format(record) ⇒ Object



387
388
389
390
391
392
393
394
395
# File 'lib/fluent/plugin/out_bigquery.rb', line 387

def format(record)
  out = {}
  @fields.each do |key, schema|
    value = record[key]
    next if value.nil? # field does not exists, or null value
    out[key] = schema.format(value)
  end
  out
end

#register_field(name, type) ⇒ Object

Raises:

  • (ConfigError)


373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/fluent/plugin/out_bigquery.rb', line 373

def register_field(name, type)
  raise ConfigError, "field #{name} is registered twice" if @fields.key?(name)
  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
  end
end

#typeObject



365
366
367
# File 'lib/fluent/plugin/out_bigquery.rb', line 365

def type
  :record
end