Class: Fluent::BigQueryOutput::FieldSchema

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

Overview

def client_oauth # not implemented raise NotImplementedError, "OAuth needs browser authentication..."

client = Google::APIClient.new(
:application_name => 'Example Ruby application',
:application_version => '1.0.0'
)
bigquery = client.discovered_api('bigquery', 'v2')
flow = Google::APIClient::InstalledAppFlow.new(
:client_id => @client_id
:client_secret => @client_secret
:scope => ['https://www.googleapis.com/auth/bigquery']
)
client.authorization = flow.authorize # browser authentication !
client

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, mode = :nullable) ⇒ FieldSchema

Returns a new instance of FieldSchema.



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/fluent/plugin/out_bigquery.rb', line 328

def initialize(name, mode = :nullable)
  unless [:nullable, :required, :repeated].include?(mode)
    raise ConfigError, "Unrecognized mode for #{name}: #{mode}"
  end
  ### https://developers.google.com/bigquery/docs/tables
  # Each field has the following properties:
  #
  # name - Field names are any combination of uppercase and/or lowercase letters (A-Z, a-z),
  #        digits (0-9) and underscores, but no spaces. The first character must be a letter.
  unless name =~ /^[A-Za-z][_A-Za-z0-9]*$/
    raise Fluent::ConfigError, "invalid bigquery field name: '#{name}'"
  end

  @name = name
  @mode = mode
end

Instance Attribute Details

#mode ⇒ Object (readonly)

Returns the value of attribute mode.



345
346
347
# File 'lib/fluent/plugin/out_bigquery.rb', line 345

def mode
  @mode
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



345
346
347
# File 'lib/fluent/plugin/out_bigquery.rb', line 345

def name
  @name
end

Instance Method Details

#format(value) ⇒ Object



347
348
349
350
351
352
353
354
355
356
357
# File 'lib/fluent/plugin/out_bigquery.rb', line 347

def format(value)
  case @mode
  when :nullable
    format_one(value) unless value.nil?
  when :required
    raise "Required field #{name} cannot be null" if value.nil?
    format_one(value)
  when :repeated
    value.nil? ? [] : value.map {|v| format_one(v) }
  end
end

#format_one(value) ⇒ Object

Raises:

  • (NotImplementedError)


359
360
361
# File 'lib/fluent/plugin/out_bigquery.rb', line 359

def format_one(value)
  raise NotImplementedError, "Must implement in a subclass" 
end