Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure deserialization is agnostic to serialization of field order #106

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name = "Legolas"
uuid = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd"
authors = ["Beacon Biosignals, Inc."]
version = "0.5.16"
version = "0.5.17"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Accessors = "0.1"
Aqua = "0.6"
Arrow = "2"
Arrow = "2.7"
ArrowTypes = "2.3"
Compat = "3.34, 4"
ConstructionBase = "1.5"
DataFrames = "1"
Expand Down
6 changes: 5 additions & 1 deletion src/schemas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,11 @@ function _generate_record_type_definitions(schema_version::SchemaVersion, record
$Arrow.ArrowTypes.ArrowType(::Type{R}) where {R<:$R} = NamedTuple{fieldnames(R),Tuple{fieldtypes(R)...}}
$Arrow.ArrowTypes.toarrow(r::$R) = NamedTuple(r)
$Arrow.ArrowTypes.JuliaType(::Val{$record_type_arrow_name}, ::Any) = $R
$Arrow.ArrowTypes.fromarrow(::Type{<:$R}, $(keys(record_fields)...)) = $R(; $(keys(record_fields)...))
function $Arrow.ArrowTypes.fromarrowstruct(::Type{<:$R}, ::Val{fnames},
$(keys(record_fields)...)) where {fnames}
nt = NamedTuple{fnames}(($(keys(record_fields)...),))
return $R(; nt...)
end
end

return quote
Expand Down
Binary file added test/issue-94.arrow
Binary file not shown.
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ end
i::Missing
end

@schema "test.issue-94-child" Issue94Child

@version Issue94ChildV1 begin
b::Int
a::Int
end

@schema "test.issue-94-parent" Issue94Parent

@version Issue94ParentV1 begin
x::Issue94ChildV1
end


@testset "`Legolas.@version` and associated utilities for declared `Legolas.SchemaVersion`s" begin
@testset "Legolas.SchemaVersionDeclarationError" begin
@test_throws SchemaVersionDeclarationError("missing prior `@schema` declaration for `Unknown` in current module") @version(UnknownV1 > ChildV1, begin x end)
Expand Down Expand Up @@ -525,6 +539,10 @@ end
@test roundtripped.n[1] == NestedV1(; gc=GrandchildV1(r0_roundtripped), k="test")
@test roundtripped.h[1] == 3

@testset "deserialization agnostic to serialized field order" begin
@test Arrow.Table("issue-94.arrow").x[1] == Issue94ChildV1(; a=1, b=2)
end

@testset "docstring support" begin
ds = string(@doc DocumentedV1)
@test contains(ds, "Very detailed documentation")
Expand Down
Loading