This is an automated email from the ASF dual-hosted git repository.

quinnj pushed a commit to branch jq-new-decimal-widths
in repository https://gitbox.apache.org/repos/asf/arrow-julia.git

commit 2e56900eec048d5512a930b587e48db7f3310656
Author: Jacob Quinn <[email protected]>
AuthorDate: Sun Sep 8 09:16:34 2024 -0600

    Support forth-coming Decimal 32/64 bitwidths
---
 src/eltypes.jl     |  6 +++---
 test/testtables.jl | 12 ++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/eltypes.jl b/src/eltypes.jl
index ffc53c0..12c7960 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,7 @@ 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 +167,7 @@ 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 1ee5404..e3636e0 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,),

Reply via email to