From 9b26669637ac80a926583edef7644c80c325b4c3 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 4 Dec 2023 16:40:43 -0600 Subject: [PATCH 1/4] support Arrow on 1.9+ via pkg extension --- Project.toml | 14 +++++++++++--- ext/JSON3ArrowExt.jl | 17 +++++++++++++++++ test/arrow.jl | 45 ++++++++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 2 ++ 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 ext/JSON3ArrowExt.jl create mode 100644 test/arrow.jl diff --git a/Project.toml b/Project.toml index 94d93d2..f567a71 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JSON3" uuid = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" authors = ["Jacob Quinn "] -version = "1.13.2" +version = "1.14.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -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"] diff --git a/ext/JSON3ArrowExt.jl b/ext/JSON3ArrowExt.jl new file mode 100644 index 0000000..d2c0b88 --- /dev/null +++ b/ext/JSON3ArrowExt.jl @@ -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 diff --git a/test/arrow.jl b/test/arrow.jl new file mode 100644 index 0000000..c9f0bf5 --- /dev/null +++ b/test/arrow.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 511a14b..e79deec 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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" From 13dfdc9723d2a713d338be344398f95450b72960 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 11 Dec 2023 11:22:20 -0600 Subject: [PATCH 2/4] bump Julia compat to 1.9 --- .github/workflows/ci.yml | 2 +- Project.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5d00c6..a7379fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: version: - - '1.6' + - '1.9' - '1' # automatically expands to the latest stable 1.x release of Julia - 'nightly' os: diff --git a/Project.toml b/Project.toml index f567a71..804d750 100644 --- a/Project.toml +++ b/Project.toml @@ -22,7 +22,7 @@ ArrowTypes = "2.2" Parsers = "0.3, 1, 2" PrecompileTools = "1" StructTypes = "1.10" -julia = "1.6" +julia = "1.9" [extras] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" From 2170a6eec471a8a7d72b2a22eac26c9ef875deed Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 11 Dec 2023 12:53:36 -0600 Subject: [PATCH 3/4] Revert "bump Julia compat to 1.9" This reverts commit 13dfdc9723d2a713d338be344398f95450b72960. --- .github/workflows/ci.yml | 2 +- Project.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7379fa..f5d00c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: version: - - '1.9' + - '1.6' - '1' # automatically expands to the latest stable 1.x release of Julia - 'nightly' os: diff --git a/Project.toml b/Project.toml index 804d750..f567a71 100644 --- a/Project.toml +++ b/Project.toml @@ -22,7 +22,7 @@ ArrowTypes = "2.2" Parsers = "0.3, 1, 2" PrecompileTools = "1" StructTypes = "1.10" -julia = "1.9" +julia = "1.6" [extras] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" From 915505862fbde6cb8d4544f8ddcd317d7b2c3c91 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 11 Dec 2023 13:18:09 -0600 Subject: [PATCH 4/4] 1.6 compat --- Project.toml | 13 +++++++------ test/runtests.jl | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index f567a71..1462d62 100644 --- a/Project.toml +++ b/Project.toml @@ -11,12 +11,6 @@ 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" @@ -24,9 +18,16 @@ PrecompileTools = "1" StructTypes = "1.10" julia = "1.6" +[extensions] +JSON3ArrowExt = ["ArrowTypes"] + [extras] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" +ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Arrow", "Test"] + +[weakdeps] +ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" diff --git a/test/runtests.jl b/test/runtests.jl index e79deec..8f7b0b1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1103,6 +1103,8 @@ y = Vector{UndefGuy}(undef, 2) y[1] = x @test JSON3.write(y) == "[{\"id\":10},null]" -@testset "Arrow" include("arrow.jl") +@static if isdefined(Base, :get_extension) + @testset "Arrow" include("arrow.jl") +end end # @testset "JSON3"