Class: Vertica::Column
- Inherits:
-
Object
- Object
- Vertica::Column
- Defined in:
- lib/vertica/column.rb
Constant Summary collapse
- STRING_CONVERTER =
lambda { |s| s.force_encoding('utf-8') }
- FLOAT_CONVERTER =
lambda do |s| case s when 'Infinity' Float::INFINITY when '-Infinity' -Float::INFINITY when 'NaN' Float::NAN else s.to_f end end
- DATA_TYPE_CONVERSIONS =
{ 0 => [:unspecified, nil], 1 => [:tuple, nil], 2 => [:pos, nil], 3 => [:record, nil], 4 => [:unknown, nil], 5 => [:bool, lambda { |s| s == 't' }], 6 => [:integer, lambda { |s| s.to_i }], 7 => [:float, FLOAT_CONVERTER], 8 => [:char, STRING_CONVERTER], 9 => [:varchar, STRING_CONVERTER], 10 => [:date, lambda { |s| Date.new(*s.split("-").map{|x| x.to_i}) }], 11 => [:time, nil], 12 => [:timestamp, lambda { |s| DateTime.parse(s, true) }], 13 => [:timestamp_tz, lambda { |s| DateTime.parse(s, true) }], 14 => [:interval, nil], 15 => [:time_tz, nil], 16 => [:numeric, lambda { |s| BigDecimal.new(s) }], 17 => [:bytea, lambda { |s| s.gsub(/\\([0-3][0-7][0-7])/) { $1.to_i(8).chr }} ], 18 => [:rle_tuple, nil], 115 => [:long_varchar, STRING_CONVERTER], }
- DATA_TYPES =
DATA_TYPE_CONVERSIONS.values.map { |t| t[0] }
Instance Attribute Summary collapse
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#table_oid ⇒ Object
readonly
Returns the value of attribute table_oid.
-
#type_modifier ⇒ Object
readonly
Returns the value of attribute type_modifier.
Instance Method Summary collapse
- #convert(s) ⇒ Object
-
#initialize(col) ⇒ Column
constructor
A new instance of Column.
Constructor Details
#initialize(col) ⇒ Column
Returns a new instance of Column.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vertica/column.rb', line 49 def initialize(col) @type_modifier = col.fetch(:type_modifier) @format = col.fetch(:format_code) == 0 ? :text : :binary @table_oid = col.fetch(:table_oid) @name = col.fetch(:name).to_sym @attribute_number = col.fetch(:attribute_number) @size = col.fetch(:data_type_size) @data_type, @converter = column_type_from_oid(col.fetch(:data_type_oid)) end |
Instance Attribute Details
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
7 8 9 |
# File 'lib/vertica/column.rb', line 7 def data_type @data_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/vertica/column.rb', line 3 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'lib/vertica/column.rb', line 6 def size @size end |
#table_oid ⇒ Object (readonly)
Returns the value of attribute table_oid.
4 5 6 |
# File 'lib/vertica/column.rb', line 4 def table_oid @table_oid end |
#type_modifier ⇒ Object (readonly)
Returns the value of attribute type_modifier.
5 6 7 |
# File 'lib/vertica/column.rb', line 5 def type_modifier @type_modifier end |
Instance Method Details
#convert(s) ⇒ Object
60 61 62 63 |
# File 'lib/vertica/column.rb', line 60 def convert(s) return unless s @converter ? @converter.call(s) : s end |