ericphanson opened a new issue, #323:
URL: https://github.com/apache/arrow-julia/issues/323
@kleinschmidt and I came up with
```julia
using Arrow: ArrowTypes
macro arrow_record(T)
name = :(Symbol("JuliaLang.", @__MODULE__, ".", string(parentmodule($T),
'.', nameof($T))))
return quote
ArrowTypes.arrowname(::Type{$T}) = $name
ArrowTypes.ArrowType(::Type{$T}) = fieldtypes($T)
ArrowTypes.toarrow(obj::$T) = ntuple(i -> getfield(obj, i),
fieldcount($T))
ArrowTypes.JuliaType(::Val{$name}, ::Any) = $T
ArrowTypes.fromarrow(::Type{$T}, args...) = $T(args...)
end
end
```
as a quick way to declare that a non-parametrized concrete type should be
serialized like a "record" (a la
[`StructTypes.StructType`](https://juliadata.github.io/StructTypes.jl/stable/#StructTypes.Struct)).
(Or maybe it should be called `@arrow_fields` or something?). In other words,
we want it to just serialize out as a tuple of its fields with a metadata tag.
This could be used as, e.g.
```julia
using Arrow
struct Foo
bar::String
x::Int
end
@arrow_record Foo
my_foo = Foo("hi", 1)
table = [(; foo_col=my_foo)]
roundtripped_table = Arrow.Table(Arrow.tobuffer(table))
using Test
@test roundtripped_table.foo_col[1] == my_foo # true
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]