Skip to content

Commit

Permalink
support Arrow on 1.9+ via pkg extension (#274)
Browse files Browse the repository at this point in the history
* support Arrow on 1.9+ via pkg extension

* bump Julia compat to 1.9

* Revert "bump Julia compat to 1.9"

This reverts commit 13dfdc9.

* 1.6 compat
  • Loading branch information
palday authored Dec 15, 2023
1 parent 0480e3f commit 6429ada
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
15 changes: 12 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 @@ -12,13 +12,22 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

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

[extensions]
JSON3ArrowExt = ["ArrowTypes"]

[extras]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Arrow", "Test"]

[weakdeps]
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
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
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1103,4 +1103,8 @@ y = Vector{UndefGuy}(undef, 2)
y[1] = x
@test JSON3.write(y) == "[{\"id\":10},null]"

@static if isdefined(Base, :get_extension)
@testset "Arrow" include("arrow.jl")
end

end # @testset "JSON3"

2 comments on commit 6429ada

@quinnj
Copy link
Owner

@quinnj quinnj commented on 6429ada Dec 15, 2023

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/97146

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.14.0 -m "<description of version>" 6429adafd02a7ad07fa80e9a0ad21b098635244c
git push origin v1.14.0

Please sign in to comment.