Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Arrow on 1.9+ via pkg extension #274

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 11 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JSON3"
uuid = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
authors = ["Jacob Quinn <[email protected]>"]
version = "1.13.2"
version = "1.14.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -11,14 +11,22 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[weakdeps]
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"

[extensions]
JSON3ArrowExt = ["ArrowTypes"]

[compat]
ArrowTypes = "2.2"
Parsers = "0.3, 1, 2"
PrecompileTools = "1"
StructTypes = "1.10"
julia = "1.6"
PrecompileTools = "1"

[extras]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Arrow", "Test"]
17 changes: 17 additions & 0 deletions ext/JSON3ArrowExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module JSON3ArrowExt

using JSON3
using ArrowTypes

const JSON3_ARROW_NAME = Symbol("JuliaLang.JSON3.Object")

# It might looks strange to have this as a StructKind when JSON objects are
# very dict-like, but the valtype is Any, which Arrow.jl really not like
# and even if we add a
# toarrow(d::JSON3.Object) d = Dict{String, Union{typeof.(values(d))...}
# that does not seem to solve the problem.
ArrowTypes.ArrowKind(::Type{<:JSON3.Object}) = ArrowTypes.StructKind()
ArrowTypes.arrowname(::Type{<:JSON3.Object}) = JSON3_ARROW_NAME
ArrowTypes.JuliaType(::Val{JSON3_ARROW_NAME}) = JSON3.Object

end # module
45 changes: 45 additions & 0 deletions test/arrow.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Arrow

obj1 = JSON3.read("""
{
"int": 1,
"float": 2.1
}
""")

obj2 = JSON3.read("""
{
"int": 1,
"float": 2.1,
"bool1": true,
"bool2": false,
"none": null,
"str": "\\"hey there sailor\\"",
"arr": [null, 1, "hey"],
"arr2": [1.2, 3.4, 5.6]
}
""")

obj3 = JSON3.read("""
{
"int": 1,
"float": 2.1,
"bool1": true,
"bool2": false,
"none": null,
"str": "\\"hey there sailor\\"",
"obj": {
"a": 1,
"b": null,
"c": [null, 1, "hey"],
"d": [1.2, 3.4, 5.6]
},
"arr": [null, 1, "hey"],
"arr2": [1.2, 3.4, 5.6]
}
""")

tbl = (; json=[obj1, obj2, obj3])

arrow = Arrow.Table(Arrow.tobuffer(tbl))
@test tbl.json == arrow.json
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1103,4 +1103,6 @@ y = Vector{UndefGuy}(undef, 2)
y[1] = x
@test JSON3.write(y) == "[{\"id\":10},null]"

@testset "Arrow" include("arrow.jl")

end # @testset "JSON3"
Loading