Module: DuckDB::Converter
- Included in:
- Appender, PreparedStatement
- Defined in:
- lib/duckdb/converter.rb,
ext/duckdb/conveter.c
Constant Summary collapse
- HALF_HUGEINT_BIT =
64
- HALF_HUGEINT =
1 << HALF_HUGEINT_BIT
- FLIP_HUGEINT =
1 << 63
Class Method Summary collapse
- ._to_date(year, month, day) ⇒ Object
- ._to_decimal_from_vector(_width, scale, lower, upper) ⇒ Object
- ._to_hugeint_from_vector(lower, upper) ⇒ Object
- ._to_interval_from_vector(months, days, micros) ⇒ Object
- ._to_time(year, month, day, hour, minute, second, microsecond) ⇒ Object
- ._to_uuid_from_vector(lower, upper) ⇒ Object
Class Method Details
._to_date(year, month, day) ⇒ Object
14 15 16 |
# File 'lib/duckdb/converter.rb', line 14 def _to_date(year, month, day) Date.new(year, month, day) end |
._to_decimal_from_vector(_width, scale, lower, upper) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/duckdb/converter.rb', line 26 def _to_decimal_from_vector(_width, scale, lower, upper) v = _to_hugeint_from_vector(lower, upper).to_s v = v.rjust(scale + 1, '0') if v.length < scale v[-scale, 0] = '.' BigDecimal(v) end |
._to_hugeint_from_vector(lower, upper) ⇒ Object
22 23 24 |
# File 'lib/duckdb/converter.rb', line 22 def _to_hugeint_from_vector(lower, upper) (upper << HALF_HUGEINT_BIT) + lower end |
._to_interval_from_vector(months, days, micros) ⇒ Object
33 34 35 |
# File 'lib/duckdb/converter.rb', line 33 def _to_interval_from_vector(months, days, micros) Interval.new(interval_months: months, interval_days: days, interval_micros: micros) end |
._to_time(year, month, day, hour, minute, second, microsecond) ⇒ Object
18 19 20 |
# File 'lib/duckdb/converter.rb', line 18 def _to_time(year, month, day, hour, minute, second, microsecond) Time.local(year, month, day, hour, minute, second, microsecond) end |
._to_uuid_from_vector(lower, upper) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/duckdb/converter.rb', line 37 def _to_uuid_from_vector(lower, upper) upper = upper ^ FLIP_HUGEINT upper += HALF_HUGEINT if upper.negative? str = _to_hugeint_from_vector(lower, upper).to_s(16).rjust(32, '0') "#{str[0, 8]}-#{str[8, 4]}-#{str[12, 4]}-#{str[16, 4]}-#{str[20, 12]}" end |