lib/duckdb/converter.rb in duckdb-0.9.2.3 vs lib/duckdb/converter.rb in duckdb-0.10.0.0

- old
+ new

@@ -2,10 +2,12 @@ require 'date' require_relative 'interval' module DuckDB + QueryProgress = Struct.new(:percentage, :rows_processed, :total_rows_to_process) + module Converter HALF_HUGEINT_BIT = 64 HALF_HUGEINT = 1 << HALF_HUGEINT_BIT FLIP_HUGEINT = 1 << 63 @@ -33,14 +35,19 @@ def _to_hugeint_from_vector(lower, upper) (upper << HALF_HUGEINT_BIT) + lower end - def _to_decimal_from_vector(_width, scale, lower, upper) - v = _to_hugeint_from_vector(lower, upper).to_s + def _to_decimal_from_hugeint(width, scale, upper, lower = nil) + v = lower.nil? ? upper : _to_hugeint_from_vector(lower, upper) + _to_decimal_from_value(width, scale, v) + end + + def _to_decimal_from_value(_width, scale, value) + v = value.to_s v = v.rjust(scale + 1, '0') if v.length < scale - v[-scale, 0] = '.' + v[-scale, 0] = '.' if scale.positive? BigDecimal(v) end def _to_interval_from_vector(months, days, micros) Interval.new(interval_months: months, interval_days: days, interval_micros: micros) @@ -76,9 +83,13 @@ Time.parse(value) rescue StandardError => e raise(ArgumentError, "Cannot parse `#{value.inspect}` to Time object. #{e.message}") end end + end + + def _to_query_progress(percentage, rows_processed, total_rows_to_process) + DuckDB::QueryProgress.new(percentage, rows_processed, total_rows_to_process).freeze end private def integer_to_hugeint(value)