class Fluent::BigQuery::FieldSchema
Attributes
Public Class Methods
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 6 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 - The name must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_), # and must start with a letter or underscore. The maximum length is 128 characters. # https://cloud.google.com/bigquery/docs/reference/v2/tables#schema.fields.name unless name =~ /^[_A-Za-z][_A-Za-z0-9]{,127}$/ raise ConfigError, "invalid bigquery field name: '#{name}'" end @name = name @mode = mode end
Public Instance Methods
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 26 def format(value, is_load: false) case @mode when :nullable format_one(value, is_load: is_load) unless value.nil? when :required if value.nil? log.warn "Required field #{name} cannot be null" nil else format_one(value, is_load: is_load) end when :repeated value.nil? ? [] : value.each_with_object([]) { |v, arr| arr << format_one(v, is_load: true) if v } end end
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 42 def format_one(value, is_load: false) raise NotImplementedError, "Must implement in a subclass" end
Source
# File lib/fluent/plugin/bigquery/schema.rb, line 46 def to_h { :name => name, :type => type.to_s.upcase, :mode => mode.to_s.upcase, } end