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 73a6982 add IPv4/IPv6 support to ArrowTypes (#390)
73a6982 is described below
commit 73a6982df3dbd9c7c877de05351b7e3b26a3d493
Author: Ben Baumgold <[email protected]>
AuthorDate: Sat Mar 4 23:18:35 2023 -0500
add IPv4/IPv6 support to ArrowTypes (#390)
---
src/ArrowTypes/Project.toml | 5 ++++-
src/ArrowTypes/src/ArrowTypes.jl | 17 +++++++++++++++++
src/ArrowTypes/test/runtests.jl | 2 +-
src/ArrowTypes/test/tests.jl | 17 +++++++++++++++++
4 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/ArrowTypes/Project.toml b/src/ArrowTypes/Project.toml
index 7c23ce9..bad3951 100644
--- a/src/ArrowTypes/Project.toml
+++ b/src/ArrowTypes/Project.toml
@@ -21,6 +21,7 @@ authors = ["quinnj <[email protected]>"]
version = "2.0.2"
[deps]
+Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[compat]
@@ -28,7 +29,9 @@ julia = "1.0"
[extras]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
+Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
+UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[targets]
-test = ["Test", "Random"]
+test = ["Test", "Random", "Sockets", "UUIDs"]
diff --git a/src/ArrowTypes/src/ArrowTypes.jl b/src/ArrowTypes/src/ArrowTypes.jl
index 43c9c10..1351166 100644
--- a/src/ArrowTypes/src/ArrowTypes.jl
+++ b/src/ArrowTypes/src/ArrowTypes.jl
@@ -20,6 +20,7 @@ in order to signal how they should be serialized in the arrow
format.
"""
module ArrowTypes
+using Sockets
using UUIDs
export ArrowKind, NullKind, PrimitiveKind, BoolKind, ListKind,
FixedSizeListKind, MapKind, StructKind, UnionKind, DictEncodedKind, toarrow,
arrowname, fromarrow, ToArrow
@@ -234,6 +235,22 @@ arrowname(::Type{UUID}) = UUIDSYMBOL
JuliaType(::Val{UUIDSYMBOL}) = UUID
fromarrow(::Type{UUID}, x::NTuple{16, UInt8}) = UUID(_cast(UInt128, x))
+ArrowKind(::Type{IPv4}) = PrimitiveKind()
+ArrowType(::Type{IPv4}) = UInt32
+toarrow(x::IPv4) = x.host
+const IPV4_SYMBOL = Symbol("JuliaLang.IPv4")
+arrowname(::Type{IPv4}) = IPV4_SYMBOL
+JuliaType(::Val{IPV4_SYMBOL}) = IPv4
+fromarrow(::Type{IPv4}, x::Integer) = IPv4(x)
+
+ArrowKind(::Type{IPv6}) = FixedSizeListKind{16, UInt8}()
+ArrowType(::Type{IPv6}) = NTuple{16, UInt8}
+toarrow(x::IPv6) = _cast(NTuple{16, UInt8}, x.host)
+const IPV6_SYMBOL = Symbol("JuliaLang.IPv6")
+arrowname(::Type{IPv6}) = IPV6_SYMBOL
+JuliaType(::Val{IPV6_SYMBOL}) = IPv6
+fromarrow(::Type{IPv6}, x::NTuple{16, UInt8}) = IPv6(_cast(UInt128, x))
+
function _cast(::Type{Y}, x)::Y where {Y}
y = Ref{Y}()
_unsafe_cast!(y, Ref(x), 1)
diff --git a/src/ArrowTypes/test/runtests.jl b/src/ArrowTypes/test/runtests.jl
index 7c9ab35..adeaf01 100644
--- a/src/ArrowTypes/test/runtests.jl
+++ b/src/ArrowTypes/test/runtests.jl
@@ -15,6 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-using Test, ArrowTypes, UUIDs
+using Test, ArrowTypes, UUIDs, Sockets
include("tests.jl")
diff --git a/src/ArrowTypes/test/tests.jl b/src/ArrowTypes/test/tests.jl
index 71be73e..e035b48 100644
--- a/src/ArrowTypes/test/tests.jl
+++ b/src/ArrowTypes/test/tests.jl
@@ -104,6 +104,23 @@ ubytes = ArrowTypes._cast(NTuple{16, UInt8}, u.value)
@test ArrowTypes.JuliaType(Val(ArrowTypes.UUIDSYMBOL)) == UUID
@test ArrowTypes.fromarrow(UUID, ubytes) == u
+ip4 = IPv4(rand(UInt32))
+@test ArrowTypes.ArrowKind(ip4) == PrimitiveKind()
+@test ArrowTypes.ArrowType(IPv4) == UInt32
+@test ArrowTypes.toarrow(ip4) == ip4.host
+@test ArrowTypes.arrowname(IPv4) == ArrowTypes.IPV4_SYMBOL
+@test ArrowTypes.JuliaType(Val(ArrowTypes.IPV4_SYMBOL)) == IPv4
+@test ArrowTypes.fromarrow(IPv4, ip4.host) == ip4
+
+ip6 = IPv6(rand(UInt128))
+ip6_ubytes = ArrowTypes._cast(NTuple{16, UInt8}, ip6.host)
+@test ArrowTypes.ArrowKind(ip6) == ArrowTypes.FixedSizeListKind{16, UInt8}()
+@test ArrowTypes.ArrowType(IPv6) == NTuple{16, UInt8}
+@test ArrowTypes.toarrow(ip6) == ip6_ubytes
+@test ArrowTypes.arrowname(IPv6) == ArrowTypes.IPV6_SYMBOL
+@test ArrowTypes.JuliaType(Val(ArrowTypes.IPV6_SYMBOL)) == IPv6
+@test ArrowTypes.fromarrow(IPv6, ip6_ubytes) == ip6
+
nt = (id=1, name="bob")
@test ArrowTypes.ArrowKind(NamedTuple) == ArrowTypes.StructKind()
@test ArrowTypes.fromarrow(typeof(nt), nt) === nt