Skip to content

Issues deconstructing optional structs #18

@garborg

Description

@garborg

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions