From 1ca78bc3b0ac4b3d71de1704bacf6a4bda265c34 Mon Sep 17 00:00:00 2001 From: Hannah Robertson Date: Thu, 8 Jun 2023 13:41:18 -0400 Subject: [PATCH] Add `accepted_field_type` for abstract vectors (#89) * add accepted_field_type for abstract vectors * Update src/schemas.jl Co-authored-by: Jarrett Revels * incorporate jrevels suggestion --------- Co-authored-by: Jarrett Revels --- Project.toml | 2 +- src/schemas.jl | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 95d3f84..865b7d7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Legolas" uuid = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd" authors = ["Beacon Biosignals, Inc."] -version = "0.5.9" +version = "0.5.10" [deps] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" diff --git a/src/schemas.jl b/src/schemas.jl index c109e6a..e48bdc4 100644 --- a/src/schemas.jl +++ b/src/schemas.jl @@ -241,7 +241,10 @@ Legolas itself defines the following default overloads: accepted_field_type(::SchemaVersion, T::Type) = T accepted_field_type(::SchemaVersion, ::Type{UUID}) = Union{UUID,UInt128} - accepted_field_type(::SchemaVersion, ::Type{Symbol}) = Union{Symbol,String} + accepted_field_type(::SchemaVersion, ::Type{Symbol}) = Union{Symbol,AbstractString} + accepted_field_type(::SchemaVersion, ::Type{String}) = AbstractString + accepted_field_type(sv::SchemaVersion, ::Type{<:Vector{T}}) where T = AbstractVector{<:(accepted_field_type(sv, T))} + accepted_field_type(::SchemaVersion, ::Type{Vector}) = AbstractVector Outside of these default overloads, this function should only be overloaded against specific `SchemaVersion`s that are authored within the same module as the overload definition; to do @@ -249,7 +252,10 @@ otherwise constitutes type piracy and should be avoided. """ @inline accepted_field_type(::SchemaVersion, T::Type) = T accepted_field_type(::SchemaVersion, ::Type{UUID}) = Union{UUID,UInt128} -accepted_field_type(::SchemaVersion, ::Type{Symbol}) = Union{Symbol,String} +accepted_field_type(::SchemaVersion, ::Type{Symbol}) = Union{Symbol,AbstractString} +accepted_field_type(::SchemaVersion, ::Type{String}) = AbstractString +accepted_field_type(sv::SchemaVersion, ::Type{<:Vector{T}}) where T = AbstractVector{<:(accepted_field_type(sv, T))} +accepted_field_type(::SchemaVersion, ::Type{Vector}) = AbstractVector """ Legolas.find_violation(ts::Tables.Schema, sv::Legolas.SchemaVersion) @@ -273,7 +279,7 @@ find_violation(::Tables.Schema, sv::SchemaVersion) = throw(UnknownSchemaVersionE Return a `Vector{Pair{Symbol,Union{Type,Missing}}}` of all of `ts`'s violations with respect to `sv`. -This function's notion of "violation" is defined by [`Legolas.find_violation`](@ref), which immediately returns the first violation found; prefer to use that function instead of `find_violations` in situations where you only need to detect *any* violation instead of *all* violations. +This function's notion of "violation" is defined by [`Legolas.find_violation`](@ref), which immediately returns the first violation found; prefer to use that function instead of `find_violations` in situations where you only need to detect *any* violation instead of *all* violations. See also: [`Legolas.validate`](@ref), [`Legolas.complies_with`](@ref), [`Legolas.find_violation`](@ref). """