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"
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.
-
#zone_offset ⇒ Object
readonly
Returns the value of attribute zone_offset.
Class Method Summary collapse
-
.create_converters(schema, default_timezone, column_options) ⇒ Hash
Hash whose key is column_name, and value is its converter (Proc).
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.
29 30 31 32 33 34 35 36 37 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 29 def initialize(schema_type, value_type = nil, = nil, timezone = nil) @schema_type = schema_type @value_type = value_type || schema_type.to_s if @schema_type == :timestamp || @value_type == 'timestamp' @timestamp_format = @timezone = timezone @zone_offset = get_zone_offset(@timezone) if @timezone end end |
Instance Attribute Details
#schema_type ⇒ Object (readonly)
Returns the value of attribute schema_type.
8 9 10 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 8 def schema_type @schema_type end |
#timestamp_format ⇒ Object (readonly)
Returns the value of attribute timestamp_format.
8 9 10 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 8 def @timestamp_format end |
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
8 9 10 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 8 def timezone @timezone end |
#value_type ⇒ Object (readonly)
Returns the value of attribute value_type.
8 9 10 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 8 def value_type @value_type end |
#zone_offset ⇒ Object (readonly)
Returns the value of attribute zone_offset.
8 9 10 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 8 def zone_offset @zone_offset end |
Class Method Details
.create_converters(schema, default_timezone, column_options) ⇒ Hash
Returns hash whose key is column_name, and value is its converter (Proc).
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 16 def self.create_converters(schema, default_timezone, ) 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'] || DEFAULT_TIMESTAMP_FORMAT timezone = [column_name]['timezone'] || default_timezone [column_name, self.new(schema_type, value_type, , timezone).create_converter] else [column_name, self.new(schema_type, nil, nil, default_timezone).create_converter] end end] end |
Instance Method Details
#boolean_converter ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 50 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
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 39 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
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 69 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| val ? Time.at(val).localtime(zone_offset) : nil } else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for double column" end end |
#long_converter ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 58 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| val ? Time.at(val).localtime(zone_offset) : nil } else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for long column" end end |
#string_converter ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 80 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| val ? strptime_with_zone(val, , zone_offset) : nil } else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for string column" end end |
#timestamp_converter ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/embulk/output/vertica/value_converter_factory.rb', line 91 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 ? val.localtime(zone_offset).strftime() : nil } when 'timestamp' then Proc.new {|val| val ? val.localtime(zone_offset) : nil } else raise NotSupportedType, "embulk-output-vertica cannot take column value_type #{value_type} for timesatmp column" end end |