Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,14 @@ def initialize(byte_width, precision, scale)
@precision = precision
@scale = scale
end

def to_flatbuffers
fb_type = FB::Decimal::Data.new
fb_type.bit_width = @byte_width * 8
fb_type.precision = @precision
fb_type.scale = @scale
fb_type
end
end

class Decimal128Type < DecimalType
Expand Down
62 changes: 62 additions & 0 deletions ruby/red-arrow-format/test/test-writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def convert_type(red_arrow_type)
ArrowFormat::UTF8Type.singleton
when Arrow::LargeStringDataType
ArrowFormat::LargeUTF8Type.singleton
when Arrow::Decimal128DataType
ArrowFormat::Decimal128Type.new(red_arrow_type.precision,
red_arrow_type.scale)
when Arrow::Decimal256DataType
ArrowFormat::Decimal256Type.new(red_arrow_type.precision,
red_arrow_type.scale)
when Arrow::FixedSizeBinaryDataType
ArrowFormat::FixedSizeBinaryType.new(red_arrow_type.byte_width)
else
Expand Down Expand Up @@ -444,6 +450,62 @@ def test_write
@values)
end
end

sub_test_case("Decimal128") do
def build_array
@positive_small = "1.200"
@positive_large = ("1234567890" * 3) + "12345.678"
@negative_small = "-1.200"
@negative_large = "-" + ("1234567890" * 3) + "12345.678"
Arrow::Decimal128Array.new({precision: 38, scale: 3},
[
@positive_large,
@positive_small,
nil,
@negative_small,
@negative_large,
])
end

def test_write
assert_equal([
BigDecimal(@positive_large),
BigDecimal(@positive_small),
nil,
BigDecimal(@negative_small),
BigDecimal(@negative_large),
],
@values)
end
end

sub_test_case("Decimal256") do
def build_array
@positive_small = "1.200"
@positive_large = ("1234567890" * 7) + "123.456"
@negative_small = "-1.200"
@negative_large = "-" + ("1234567890" * 7) + "123.456"
Arrow::Decimal256Array.new({precision: 76, scale: 3},
[
@positive_large,
@positive_small,
nil,
@negative_small,
@negative_large,
])
end

def test_write
assert_equal([
BigDecimal(@positive_large),
BigDecimal(@positive_small),
nil,
BigDecimal(@negative_small),
BigDecimal(@negative_large),
],
@values)
end
end
end
end
end
Expand Down
Loading