Skip to content
Permalink
Browse files
fix 232 (incorrectly serialized non-concrete Dict type) by disallowin…
…g non-concrete map-like types (#305)
  • Loading branch information
jrevels committed Mar 18, 2022
1 parent f88a62e commit 82085a0353d05a54787a241749d2df138898c98a
Showing 2 changed files with 18 additions and 9 deletions.
@@ -51,7 +51,10 @@ function arrowvector(::MapKind, x, i, nl, fi, de, ded, meta; largelists::Bool=fa
validity = ValidityBitmap(x)
ET = eltype(x)
DT = Base.nonmissingtype(ET)
KT = KeyValue{keytype(DT), valtype(DT)}
KDT, VDT = keytype(DT), valtype(DT)
ArrowTypes.concrete_or_concreteunion(KDT) || throw(ArgumentError("`keytype(d)` must be concrete to serialize map-like `d`, but `keytype(d) == $KDT`"))
ArrowTypes.concrete_or_concreteunion(VDT) || throw(ArgumentError("`valtype(d)` must be concrete to serialize map-like `d`, but `valtype(d) == $VDT`"))
KT = KeyValue{KDT,VDT}
VT = Vector{KT}
T = DT !== ET ? Union{Missing, VT} : VT
flat = ToList(T[keyvalues(KT, y) for y in x]; largelists=largelists)
@@ -359,15 +359,14 @@ tbl = Arrow.Table(bytes)
@test eltype(tbl.a) == Union{Int64, Missing}

# 181
tbl = (x = [Dict()],)
d = tbl.x[];
for i in 1:20
d[i] = Dict()
d = d[i]
d = Dict{Int,Int}()
for i in 1:9
d = Dict(i => d)
end
msg = "reached nested serialization level (42) deeper than provided max depth argument (41); to increase allowed nesting level, pass `maxdepth=X`"
@test_throws ErrorException(msg) Arrow.tobuffer(tbl; maxdepth=41).x
@test Arrow.Table(Arrow.tobuffer(tbl; maxdepth=42)).x == tbl.x
tbl = (x = [d],)
msg = "reached nested serialization level (20) deeper than provided max depth argument (19); to increase allowed nesting level, pass `maxdepth=X`"
@test_throws ErrorException(msg) Arrow.tobuffer(tbl; maxdepth=19)
@test Arrow.Table(Arrow.tobuffer(tbl; maxdepth=20)).x == tbl.x

# 167
t = (
@@ -491,6 +490,13 @@ t2 = (
# https://github.com/apache/arrow-julia/issues/253
@test Arrow.toidict(Pair{String, String}[]) == Base.ImmutableDict{String, String}()

t = (; x=[Dict(true => 1.32, 1.2 => 0.53495216)])
@test_throws ArgumentError("`keytype(d)` must be concrete to serialize map-like `d`, but `keytype(d) == Real`") Arrow.tobuffer(t)
t = (; x=[Dict(32.0 => true, 1.2 => 0.53495216)])
@test_throws ArgumentError("`valtype(d)` must be concrete to serialize map-like `d`, but `valtype(d) == Real`") Arrow.tobuffer(t)
t = (; x=[Dict(true => 1.32, 1.2 => true)])
@test_throws ArgumentError("`keytype(d)` must be concrete to serialize map-like `d`, but `keytype(d) == Real`") Arrow.tobuffer(t)

end # @testset "misc"

end

0 comments on commit 82085a0

Please sign in to comment.