Class: Fluent::BigQueryOutput::FieldSchema
- Inherits:
-
Object
- Object
- Fluent::BigQueryOutput::FieldSchema
- Defined in:
- lib/fluent/plugin/out_bigquery.rb
Direct Known Subclasses
BooleanFieldSchema, FloatFieldSchema, IntegerFieldSchema, RecordSchema, StringFieldSchema, TimestampFieldSchema
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #format(value) ⇒ Object
- #format_one(value) ⇒ Object
-
#initialize(name, mode = :nullable) ⇒ FieldSchema
constructor
A new instance of FieldSchema.
- #to_h ⇒ Object
Constructor Details
#initialize(name, mode = :nullable) ⇒ FieldSchema
Returns a new instance of FieldSchema.
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/fluent/plugin/out_bigquery.rb', line 641 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 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.
659 660 661 |
# File 'lib/fluent/plugin/out_bigquery.rb', line 659 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
659 660 661 |
# File 'lib/fluent/plugin/out_bigquery.rb', line 659 def name @name end |
Instance Method Details
#format(value) ⇒ Object
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
# File 'lib/fluent/plugin/out_bigquery.rb', line 661 def format(value) case @mode when :nullable format_one(value) unless value.nil? when :required if value.nil? log.warn "Required field #{name} cannot be null" nil else format_one(value) end when :repeated value.nil? ? [] : value.map {|v| format_one(v) } end end |
#format_one(value) ⇒ Object
677 678 679 |
# File 'lib/fluent/plugin/out_bigquery.rb', line 677 def format_one(value) raise NotImplementedError, "Must implement in a subclass" end |
#to_h ⇒ Object
681 682 683 684 685 686 687 |
# File 'lib/fluent/plugin/out_bigquery.rb', line 681 def to_h { :name => name, :type => type.to_s.upcase, :mode => mode.to_s.upcase, } end |