[ArrowTypes] add `@arrow_record`?
- Dominant language
- Julia
- Stars
- 312
- Forks
- 78
- PR merge metrics
- No merged PRs in 30d
Description
@kleinschmidt and I came up with
```julia
using Arrow: ArrowTypes
macro arrow_record(T1)
T = esc(T1)
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
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the existing ArrowTypes.arrowname, ArrowType, toarrow, JuliaType, and fromarrow methods used for custom serialization. Confirm how a non-parametrized concrete record type should be represented and named, then use the Foo example as the round-trip acceptance case for Arrow.Table and Arrow.tobuffer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data-engineering
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100