diff --git a/Gemfile.lock b/Gemfile.lock index 0650f4f..371fb94 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,21 +1,21 @@ PATH remote: . specs: - parqueteur (1.3.0) + parqueteur (1.3.1) red-parquet (~> 5.0) GEM remote: https://rubygems.org/ specs: - bigdecimal (3.0.0) - extpp (0.0.9) - gio2 (3.4.6) - gobject-introspection (= 3.4.6) - glib2 (3.4.6) + bigdecimal (3.0.2) + extpp (0.1.0) + gio2 (3.4.9) + gobject-introspection (= 3.4.9) + glib2 (3.4.9) native-package-installer (>= 1.0.3) pkg-config (>= 1.3.5) - gobject-introspection (3.4.6) - glib2 (= 3.4.6) + gobject-introspection (3.4.9) + glib2 (= 3.4.9) native-package-installer (1.1.1) pkg-config (1.4.6) rake (13.0.6) diff --git a/examples/hello-world.rb b/examples/hello-world.rb index 8cc2cff..a7456d8 100644 --- a/examples/hello-world.rb +++ b/examples/hello-world.rb @@ -22,7 +22,7 @@ class FooParquetConverter < Parqueteur::Converter 'id' => i, 'my_string_array' => %w[a b c], 'my_date' => Date.today, - 'my_decimal' => BigDecimal('789000.5678'), + 'my_decimal' => BigDecimal('0.03'), 'my_int' => rand(1..10), 'my_map' => { 'a' => 'b' }, 'my_string' => 'Hello World', @@ -52,5 +52,6 @@ class FooParquetConverter < Parqueteur::Converter # Arrow Table table = converter.to_arrow_table table.each_record do |record| + # pp record['my_decimal'].to_f pp record.to_h end diff --git a/lib/parqueteur/types/decimal128_type.rb b/lib/parqueteur/types/decimal128_type.rb index 046a823..9462b9d 100644 --- a/lib/parqueteur/types/decimal128_type.rb +++ b/lib/parqueteur/types/decimal128_type.rb @@ -3,14 +3,25 @@ module Parqueteur module Types class Decimal128Type < Parqueteur::Type + def initialize(options = {}, &block) + @scale = options.fetch(:scale) + @precision = options.fetch(:precision) + @format_str = "%.#{@scale}f" + super(options, &block) + end + def build_value_array(values) - Arrow::Decimal128ArrayBuilder.build(@arrow_type, values) + Arrow::Decimal128ArrayBuilder.build( + @arrow_type, + values.map do |value| + Arrow::Decimal128.new(format(@format_str, BigDecimal(value))) + end + ) end def arrow_type_builder Arrow::Decimal128DataType.new( - precision: @options.fetch(:precision), - scale: @options.fetch(:scale) + @precision, @scale ) end end diff --git a/lib/parqueteur/types/decimal256_type.rb b/lib/parqueteur/types/decimal256_type.rb index 3b0f175..912c1c9 100644 --- a/lib/parqueteur/types/decimal256_type.rb +++ b/lib/parqueteur/types/decimal256_type.rb @@ -3,14 +3,25 @@ module Parqueteur module Types class Decimal256Type < Parqueteur::Type + def initialize(options = {}, &block) + @scale = options.fetch(:scale) + @precision = options.fetch(:precision) + @format_str = "%.#{@scale}f" + super(options, &block) + end + def build_value_array(values) - Arrow::Decimal256ArrayBuilder.build(@arrow_type, values) + Arrow::Decimal256ArrayBuilder.build( + @arrow_type, + values.map do |value| + Arrow::Decimal256.new(format(@format_str, BigDecimal(value))) + end + ) end def arrow_type_builder Arrow::Decimal256DataType.new( - precision: @options.fetch(:precision), - scale: @options.fetch(:scale) + @precision, @scale ) end end diff --git a/lib/parqueteur/version.rb b/lib/parqueteur/version.rb index 3a2c602..c4f68aa 100644 --- a/lib/parqueteur/version.rb +++ b/lib/parqueteur/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Parqueteur - VERSION = '1.3.0' + VERSION = '1.3.1' end