Skip to content

Commit d8094b8

Browse files
committed
Add package extension to support InlineStrings in Arrow.jl
Fixes apache/arrow-julia#196. This utilizes the new package extension feature of Julia 1.9 to add a conditional dependency on the ArrowTypes.jl package. With ArrowTypes.jl, it adds the necessary overloads to allow round- tripping of inline strings through the arrow format. Other language implementations will read them as normal strings, but in the Julia implementation, the additional type metadata signal that these strings were originally inline strings and can be deserialized as such. I'm explicitly not using the Requires.jl hack for backwards compat w/ older Julia versions because I like the idea of this being sort of a "beta" feature for users already using 1.9 to see if there are any unexpected issues that pop up for inline strings in the arrow format.
1 parent b7923a2 commit d8094b8

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

Project.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ version = "1.4.0"
77
Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
88

99
[extras]
10+
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
1011
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1112
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1213
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
@@ -15,5 +16,11 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1516
Parsers = "2"
1617
julia = "1.6"
1718

19+
[weakdeps]
20+
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
21+
22+
[extensions]
23+
ArrowTypesExt = "ArrowTypes"
24+
1825
[targets]
19-
test = ["Test", "Random", "Serialization"]
26+
test = ["Arrow", "Test", "Random", "Serialization"]

ext/ArrowTypesExt.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module ArrowTypesExt
2+
3+
using ArrowTypes, InlineStrings
4+
5+
for sz in (1, 4, 8, 16, 32, 64, 128, 256)
6+
nm = Symbol(:InlineString, max(1, sz - 1))
7+
arrow_nm = Symbol("JuliaLang.InlineStrings.", nm)
8+
@eval begin
9+
ArrowTypes.arrowname(::Type{$nm}) = $(Meta.quot(arrow_nm))
10+
ArrowTypes.JuliaType(::Val{$(Meta.quot(arrow_nm))}) = $nm
11+
ArrowTypes.fromarrow(::Type{$nm}, ptr::Ptr{UInt8}, len::Int) = $nm(ptr, len)
12+
end
13+
end
14+
15+
end

ext/tests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Test, Arrow, InlineStrings
2+
3+
@testset "basic Arrow.jl interop" begin
4+
t = (x = inlinestrings(["a", "b", "sailor"]),)
5+
t2 = Arrow.Table(Arrow.tobuffer(t))
6+
@test isequal(t.x, t2.x)
7+
@test t2.x[1] isa InlineString
8+
end

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,5 @@ end
562562
@test repr(String31["foo", "bar"]) == "String31[\"foo\", \"bar\"]"
563563
@test repr(InlineString[inline1"a", inline15"a"]) == "InlineString[String1(\"a\"), String15(\"a\")]"
564564
end
565+
566+
include(joinpath(dirname(pathof(InlineStrings)), "../ext/tests.jl"))

0 commit comments

Comments
 (0)