Class: Fluent::BigQueryOutput::TimestampFieldSchema

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

Constant Summary collapse

INTEGER_REGEXP =
/\A-?[[:digit:]]+\z/.freeze
FLOAT_REGEXP =
/\A-?[[:digit:]]+(\.[[:digit:]]+)\z/.freeze

Instance Attribute Summary

Attributes inherited from FieldSchema

#mode, #name

Instance Method Summary collapse

Methods inherited from FieldSchema

#format, #initialize, #to_h

Constructor Details

This class inherits a constructor from Fluent::BigQueryOutput::FieldSchema

Instance Method Details

#format_one(value) ⇒ Object



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/fluent/plugin/out_bigquery.rb', line 705

def format_one(value)
  case value
  when Time
    value.strftime("%Y-%m-%d %H:%M:%S.%6L %:z")
  when String
    if value =~ INTEGER_REGEXP
      value.to_i
    elsif value =~ FLOAT_REGEXP
      value.to_f
    else
      begin
        Time.parse(value).strftime("%Y-%m-%d %H:%M:%S.%6L %:z")
      rescue
        value
      end
    end
  else
    value
  end
end

#typeObject



701
702
703
# File 'lib/fluent/plugin/out_bigquery.rb', line 701

def type
  :timestamp
end