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

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


The following commit(s) were added to refs/heads/main by this push:
     new 82085a0  fix 232 (incorrectly serialized non-concrete Dict type) by 
disallowing non-concrete map-like types (#305)
82085a0 is described below

commit 82085a0353d05a54787a241749d2df138898c98a
Author: Jarrett Revels <[email protected]>
AuthorDate: Fri Mar 18 16:41:51 2022 -0400

    fix 232 (incorrectly serialized non-concrete Dict type) by disallowing 
non-concrete map-like types (#305)
---
 src/arraytypes/map.jl |  5 ++++-
 test/runtests.jl      | 22 ++++++++++++++--------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/arraytypes/map.jl b/src/arraytypes/map.jl
index 3664f7d..fe1409f 100644
--- a/src/arraytypes/map.jl
+++ b/src/arraytypes/map.jl
@@ -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)
diff --git a/test/runtests.jl b/test/runtests.jl
index 09d3d6e..5ed0e4d 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -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

Reply via email to