Skip to content
Open
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
10 changes: 7 additions & 3 deletions src/eltypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,18 @@ 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))
==(a::Decimal{P,S,T}, b::Decimal{P,S,T}) where {P,S,T} = ==(a.value, b.value)
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()
Expand All @@ -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

Expand Down
12 changes: 12 additions & 0 deletions test/testtables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
Comment on lines +105 to +107
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use Int64() not Int32() here?

missing,
],
),
NamedTuple(),
(convert=false,),
Expand Down