Skip to content

Commit 2e56900

Browse files
committed
Support forth-coming Decimal 32/64 bitwidths
1 parent 2696105 commit 2e56900

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/eltypes.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ function arrowtype(b, ::Type{Bool})
150150
end
151151

152152
struct Decimal{P,S,T}
153-
value::T # only Int128 or Int256
153+
value::T # only Int32, Int64, Int128 or Int256
154154
end
155155

156156
Base.zero(::Type{Decimal{P,S,T}}) where {P,S,T} = Decimal{P,S,T}(T(0))
157157
==(a::Decimal{P,S,T}, b::Decimal{P,S,T}) where {P,S,T} = ==(a.value, b.value)
158158
Base.isequal(a::Decimal{P,S,T}, b::Decimal{P,S,T}) where {P,S,T} = isequal(a.value, b.value)
159159

160160
function juliaeltype(f::Meta.Field, x::Meta.Decimal, convert)
161-
return Decimal{x.precision,x.scale,x.bitWidth == 256 ? Int256 : Int128}
161+
return Decimal{x.precision, x.scale, x.bitWidth == 256 ? Int256 : x.bitWidth == 128 ? Int128 : x.bitWidth == 64 ? Int64 : Int32}
162162
end
163163

164164
ArrowTypes.ArrowKind(::Type{<:Decimal}) = PrimitiveKind()
@@ -167,7 +167,7 @@ function arrowtype(b, ::Type{Decimal{P,S,T}}) where {P,S,T}
167167
Meta.decimalStart(b)
168168
Meta.decimalAddPrecision(b, Int32(P))
169169
Meta.decimalAddScale(b, Int32(S))
170-
Meta.decimalAddBitWidth(b, Int32(T == Int256 ? 256 : 128))
170+
Meta.decimalAddBitWidth(b, Int32(T == Int256 ? 256 : T == Int128 ? 128 : T == Int64 ? 64 : 32))
171171
return Meta.Decimal, Meta.decimalEnd(b), nothing
172172
end
173173

test/testtables.jl

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ testtables = [
9595
zero(Arrow.Date{Arrow.Meta.DateUnit.MILLISECOND,Int64}),
9696
missing,
9797
],
98+
col21=[
99+
zero(Arrow.Decimal{Int32(2),Int32(2),Int32}),
100+
zero(Arrow.Decimal{Int32(2),Int32(2),Int32}),
101+
zero(Arrow.Decimal{Int32(2),Int32(2),Int32}),
102+
missing,
103+
],
104+
col22=[
105+
zero(Arrow.Decimal{Int32(2),Int32(2),Int64}),
106+
zero(Arrow.Decimal{Int32(2),Int32(2),Int64}),
107+
zero(Arrow.Decimal{Int32(2),Int32(2),Int64}),
108+
missing,
109+
],
98110
),
99111
NamedTuple(),
100112
(convert=false,),

0 commit comments

Comments
 (0)