Class: ClickHouse::Type::DecimalType

Inherits:
BaseType
  • Object
show all
Defined in:
lib/click_house/type/decimal_type.rb

Constant Summary collapse

MAXIMUM =
Float::DIG.next

Instance Method Summary collapse

Methods inherited from BaseType

#cast_each, #container?, #ddl?, #map?, #serialize_each, #tuple?

Instance Method Details

#cast(value, precision = MAXIMUM, _scale = nil) ⇒ Object

clickhouse: P - precision. Valid range: [ 1 : 76 ]. Determines how many decimal digits number can have (including fraction). S - scale. Valid range: [ 0 : P ]. Determines how many decimal digits fraction can have.

when Oj parser @refs stackoverflow.com/questions/47885304/deserialise-json-numbers-as-bigdecimal



13
14
15
16
17
18
19
20
21
22
# File 'lib/click_house/type/decimal_type.rb', line 13

def cast(value, precision = MAXIMUM, _scale = nil)
  case value
  when BigDecimal
    value
  when String
    BigDecimal(value)
  else
    BigDecimal(value, precision > MAXIMUM ? MAXIMUM : precision)
  end
end

#serialize(value, precision = MAXIMUM, _scale = nil) ⇒ BigDecimal

Returns:

  • (BigDecimal)


25
26
27
# File 'lib/click_house/type/decimal_type.rb', line 25

def serialize(value, precision = MAXIMUM, _scale = nil)
  cast(value, precision)
end