Class: Embulk::Output::Vertica::ValueConverterFactory
- Inherits:
-
Object
- Object
- Embulk::Output::Vertica::ValueConverterFactory
- Defined in:
- lib/embulk/output/vertica/value_converter_factory.rb
Constant Summary collapse
- DEFAULT_TIMESTAMP_FORMAT =
"%Y-%m-%d %H:%M:%S %z"- DEFAULT_TIMEZONE =
"+00:00"
Instance Attribute Summary collapse
-
#schema_type ⇒ Object
readonly
Returns the value of attribute schema_type.
-
#timestamp_format ⇒ Object
readonly
Returns the value of attribute timestamp_format.
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
-
#value_type ⇒ Object
readonly
Returns the value of attribute value_type.
Class Method Summary collapse
Instance Method Summary collapse
- #boolean_converter ⇒ Object
- #create_converter ⇒ Object
- #double_converter ⇒ Object
-
#initialize(schema_type, value_type = nil, timestamp_format = nil, timezone = nil) ⇒ ValueConverterFactory
constructor
A new instance of ValueConverterFactory.
- #long_converter ⇒ Object
- #string_converter ⇒ Object
- #timestamp_converter ⇒ Object
Constructor Details
#initialize(schema_type, value_type = nil, timestamp_format = nil, timezone = nil) ⇒ ValueConverterFactory
Returns a new instance of ValueConverterFactory.
26 27 28 29 30 31 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 26 def initialize(schema_type, value_type = nil, = nil, timezone = nil) @schema_type = schema_type @value_type = value_type || schema_type.to_s @timestampt_format = || DEFAULT_TIMESTAMP_FORMAT @timezone = timezone || DEFAULT_TIMEZONE end |
Instance Attribute Details
#schema_type ⇒ Object (readonly)
Returns the value of attribute schema_type.
5 6 7 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 5 def schema_type @schema_type end |
#timestamp_format ⇒ Object (readonly)
Returns the value of attribute timestamp_format.
5 6 7 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 5 def @timestamp_format end |
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
5 6 7 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 5 def timezone @timezone end |
#value_type ⇒ Object (readonly)
Returns the value of attribute value_type.
5 6 7 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 5 def value_type @value_type end |
Class Method Details
.create_converters(schema, column_options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 10 def self.create_converters(schema, ) # @param [Schema] schema embulk defined column types # @param [Hash] column_options user defined column types # @return [Array] value converters (array of Proc) Hash[*(schema.names.zip(schema.types).map do |column_name, schema_type| if [column_name] value_type = [column_name]['value_type'] = [column_name]['timestamp_format'] timezone = [column_name]['timezone'] [column_name, self.new(schema_type, value_type, , timezone).create_converter] else [column_name, Proc.new {|val| val }] end end.flatten!(1))] end |
Instance Method Details
#boolean_converter ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 44 def boolean_converter case value_type when 'boolean' then Proc.new {|val| val } when 'string' then Proc.new {|val| val.to_s } else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for boolean column" end end |
#create_converter ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 33 def create_converter case schema_type when :boolean then boolean_converter when :long then long_converter when :double then double_converter when :string then string_converter when :timestamp then else raise NotSupportedType, "embulk-output-vertica cannot take column type #{schema_type}" end end |
#double_converter ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 63 def double_converter case value_type when 'boolean' then Proc.new {|val| !!val } when 'long' then Proc.new {|val| val.to_i } when 'double' then Proc.new {|val| val } when 'string' then Proc.new {|val| val.to_s } when 'timestamp' then Proc.new {|val| Time.at(val).localtime(timezone) } else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for double column" end end |
#long_converter ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 52 def long_converter case value_type when 'boolean' then Proc.new {|val| !!val } when 'long' then Proc.new {|val| val } when 'double' then Proc.new {|val| val.to_f } when 'string' then Proc.new {|val| val.to_s } when 'timestamp' then Proc.new {|val| Time.at(val).localtime(timezone) } else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for long column" end end |
#string_converter ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 74 def string_converter case value_type when 'boolean' then Proc.new {|val| !!val } when 'long' then Proc.new {|val| val.to_i } when 'double' then Proc.new {|val| val.to_f } when 'string' then Proc.new {|val| val } when 'timestamp' then Proc.new {|val| Time.strptime(val, ) } # ToDo: timezone else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for string column" end end |
#timestamp_converter ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 85 def case value_type when 'boolean' then Proc.new {|val| !!val } when 'long' then Proc.new {|val| val.to_i } when 'double' then Proc.new {|val| val.to_f } when 'string' then Proc.new {|val| val.localtime(timezone).strftime() } when 'timestamp' then Proc.new {|val| val.localtime(timezone) } else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for timesatmp column" end end |