Skip to content

Commit

Permalink
ensure deserialization is agnostic to serialization of field order (#106
Browse files Browse the repository at this point in the history
)

* ensure deserialization is agnostic to serialization of field order

* Update Project.toml
  • Loading branch information
jrevels authored Dec 13, 2023
1 parent 7fff216 commit 470a3de
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
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

2 comments on commit 470a3de

@jrevels
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/97065

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.17 -m "<description of version>" 470a3deca472a76677e6b44dd38b7cb82e871544
git push origin v0.5.17

Please sign in to comment.