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

Issues deconstructing optional structs #18

Open
garborg opened this issue Oct 14, 2021 · 0 comments
Open

Issues deconstructing optional structs #18

garborg opened this issue Oct 14, 2021 · 0 comments

Comments

@garborg
Copy link

garborg commented Oct 14, 2021

Whereas #16 deals w/ constructing optional structs, here are a couple issues deconstructing them:

using Arrow: Arrow
using Strapping: Strapping
using StructTypes: StructTypes

# Types

# N.B. Making `TInterval` an alias for `Int` avoids both errors below
# const TInterval = Int
struct TInterval
    a::Int
end
StructTypes.StructType(::Type{TInterval}) = StructTypes.Struct()

struct StopLoc
    b::Int
    # N.B. Missing has the same issues as Nothing
    hours::Union{Nothing,TInterval}
end
StructTypes.StructType(::Type{StopLoc}) = StructTypes.Struct()

struct Trip
    start::StopLoc
    finish::StopLoc
end
StructTypes.StructType(::Type{Trip}) = StructTypes.Struct()

struct TripEnd
    finish::StopLoc
end
TripEnd(t::Trip) = TripEnd(t.finish)
StructTypes.StructType(::Type{TripEnd}) = StructTypes.Struct()

# Generate data

trips = [
    Trip(StopLoc(1, nothing), StopLoc(2, nothing)),
    Trip(StopLoc(2, TInterval(1)), StopLoc(3, TInterval(2))),
]

trip_ends = TripEnd.(trips)

# Deconstruct

de_trips = Strapping.deconstruct(trips)
Arrow.write("de_trips.arrow", de_trips) # => ERROR:
# LoadError: duplicate field name in NamedTuple: "finish_lng" is not unique

de_trip_ends = Strapping.deconstruct(trip_ends)
Arrow.write("de_trip_ends.arrow", de_trip_ends) # => ERROR:
# LoadError: AssertionError: fn === nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant