Class: ClickhouseRuby::Types::Float
- Defined in:
- lib/clickhouse_ruby/types/float.rb
Overview
Type handler for ClickHouse floating point types
Handles: Float32, Float64
Note: ClickHouse also supports special values: inf, -inf, nan
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#cast(value) ⇒ Float?
Converts a Ruby value to a float.
-
#deserialize(value) ⇒ Float?
Converts a value from ClickHouse to Ruby Float.
-
#serialize(value) ⇒ String
Converts a float to SQL literal.
Methods inherited from Base
#==, #hash, #initialize, #nullable?, #to_s
Constructor Details
This class inherits a constructor from ClickhouseRuby::Types::Base
Instance Method Details
#cast(value) ⇒ Float?
Converts a Ruby value to a float
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/clickhouse_ruby/types/float.rb', line 17 def cast(value) return nil if value.nil? case value when ::Float value when ::Integer value.to_f when ::String parse_string(value) when ::BigDecimal value.to_f else raise_cast_error(value) end end |
#deserialize(value) ⇒ Float?
Converts a value from ClickHouse to Ruby Float
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/clickhouse_ruby/types/float.rb', line 39 def deserialize(value) return nil if value.nil? case value when ::Float value when ::String parse_string(value) when ::Integer, ::BigDecimal, ::Rational value.to_f else raise_cast_error(value, "Cannot deserialize #{value.class} to #{name}") end end |
#serialize(value) ⇒ String
Converts a float to SQL literal
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/clickhouse_ruby/types/float.rb', line 58 def serialize(value) return "NULL" if value.nil? if value.nan? "nan" elsif value.infinite? == 1 "inf" elsif value.infinite? == -1 "-inf" else value.to_s end end |