Skip to content

Commit

Permalink
Fix #134 by requiring concrete or union of concrete element types for
Browse files Browse the repository at this point in the history
all columns when serializing
  • Loading branch information
quinnj committed Mar 25, 2021
1 parent 9f8bf99 commit 7ae96f0
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/arrowtypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,14 @@ struct ToArrow{T, A} <: AbstractVector{T}
data::A
end

@noinline concretecheck(T) = !isconcretetype(T) && !(T isa Union) &&
throw(ArgumentError("can't serialize column with abstract element type: $T. Column types must be concrete or a union of concrete types and elements must be homogenous for the arrow format"))

function ToArrow(x::A) where {A}
S = eltype(A)
T = ArrowType(S)
if S === T
concretecheck(T)
return x
elseif !isconcretetype(T) && !(T isa Union)
# arrow needs concrete types, so try to find a concrete common type, preferring unions
Expand All @@ -305,9 +309,7 @@ function ToArrow(x::A) where {A}
for i = 2:length(x)
@inbounds T = promoteunion(T, typeof(toarrow(x[i])))
end
if !isconcretetype(T) && !(T isa Union)
error("can't serialize column with abstract type: $A")
end
concretecheck(T)
end
return ToArrow{T, A}(x)
end
Expand All @@ -323,11 +325,7 @@ arrowconvert(T, x) = convert(T, x)
arrowconvert(::Type{Union{T, Missing}}, x) where {T} = arrowconvert(T, x)
arrowconvert(::Type{Union{T, Missing}}, ::Missing) where {T} = missing

const JULIA_TO_ARROW_TYPE_MAPPING = Dict{Type, Tuple{String, Type}}(
Char => ("JuliaLang.Char", UInt32),
Symbol => ("JuliaLang.Symbol", String),
UUID => ("JuliaLang.UUID", NTuple{16,UInt8}),
)
const JULIA_TO_ARROW_TYPE_MAPPING = Dict{Type, Tuple{String, Type}}()

istyperegistered(::Type{T}) where {T} = haskey(JULIA_TO_ARROW_TYPE_MAPPING, T)

Expand All @@ -338,11 +336,7 @@ function getarrowtype!(meta, ::Type{T}) where {T}
return arrowtype
end

const ARROW_TO_JULIA_TYPE_MAPPING = Dict{String, Tuple{Type, Type}}(
"JuliaLang.Char" => (Char, UInt32),
"JuliaLang.Symbol" => (Symbol, String),
"JuliaLang.UUID" => (UUID, NTuple{16,UInt8}),
)
const ARROW_TO_JULIA_TYPE_MAPPING = Dict{String, Tuple{Type, Type}}()

function extensiontype(f, meta)
if haskey(meta, "ARROW:extension:name")
Expand Down

0 comments on commit 7ae96f0

Please sign in to comment.