From 9256c8db2f3ee37bea855a37e24522e393458675 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Sun, 8 Sep 2024 09:16:34 -0600 Subject: [PATCH] Support forth-coming Decimal 32/64 bitwidths --- src/eltypes.jl | 10 +++++++--- test/testtables.jl | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/eltypes.jl b/src/eltypes.jl index ffc53c03..84904540 100644 --- a/src/eltypes.jl +++ b/src/eltypes.jl @@ -150,7 +150,7 @@ function arrowtype(b, ::Type{Bool}) end struct Decimal{P,S,T} - value::T # only Int128 or Int256 + value::T # only Int32, Int64, Int128 or Int256 end Base.zero(::Type{Decimal{P,S,T}}) where {P,S,T} = Decimal{P,S,T}(T(0)) @@ -158,7 +158,10 @@ Base.zero(::Type{Decimal{P,S,T}}) where {P,S,T} = Decimal{P,S,T}(T(0)) Base.isequal(a::Decimal{P,S,T}, b::Decimal{P,S,T}) where {P,S,T} = isequal(a.value, b.value) function juliaeltype(f::Meta.Field, x::Meta.Decimal, convert) - return Decimal{x.precision,x.scale,x.bitWidth == 256 ? Int256 : Int128} + return Decimal{x.precision, x.scale, + x.bitWidth == 256 ? Int256 : + x.bitWidth == 128 ? Int128 : + x.bitWidth == 64 ? Int64 : Int32} end ArrowTypes.ArrowKind(::Type{<:Decimal}) = PrimitiveKind() @@ -167,7 +170,8 @@ function arrowtype(b, ::Type{Decimal{P,S,T}}) where {P,S,T} Meta.decimalStart(b) Meta.decimalAddPrecision(b, Int32(P)) Meta.decimalAddScale(b, Int32(S)) - Meta.decimalAddBitWidth(b, Int32(T == Int256 ? 256 : 128)) + Meta.decimalAddBitWidth(b, + Int32(T == Int256 ? 256 : T == Int128 ? 128 : T == Int64 ? 64 : 32)) return Meta.Decimal, Meta.decimalEnd(b), nothing end diff --git a/test/testtables.jl b/test/testtables.jl index 1ee54045..e3636e09 100644 --- a/test/testtables.jl +++ b/test/testtables.jl @@ -95,6 +95,18 @@ testtables = [ zero(Arrow.Date{Arrow.Meta.DateUnit.MILLISECOND,Int64}), missing, ], + col21=[ + zero(Arrow.Decimal{Int32(2),Int32(2),Int32}), + zero(Arrow.Decimal{Int32(2),Int32(2),Int32}), + zero(Arrow.Decimal{Int32(2),Int32(2),Int32}), + missing, + ], + col22=[ + zero(Arrow.Decimal{Int32(2),Int32(2),Int64}), + zero(Arrow.Decimal{Int32(2),Int32(2),Int64}), + zero(Arrow.Decimal{Int32(2),Int32(2),Int64}), + missing, + ], ), NamedTuple(), (convert=false,),