Skip to content

Commit

Permalink
Don't store table metadata globally (#165)
Browse files Browse the repository at this point in the history
* Don't store table metadata globally

Fixes #90. There's no need to store table metadata globally when we can
just store it in the Table type itself and overload the `getmetadata`.
This should avoid metadata bloat in the global store.
  • Loading branch information
quinnj authored Apr 4, 2021
1 parent 31079b0 commit 295416d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,18 @@ struct Table <: Tables.AbstractColumns
columns::Vector{AbstractVector}
lookup::Dict{Symbol, AbstractVector}
schema::Ref{Meta.Schema}
metadata::Ref{Dict{String, String}}
end

Table() = Table(Symbol[], Type[], AbstractVector[], Dict{Symbol, AbstractVector}(), Ref{Meta.Schema}())
Table() = Table(Symbol[], Type[], AbstractVector[], Dict{Symbol, AbstractVector}(), Ref{Meta.Schema}(), Ref{Dict{String, String}}())
Table(names, types, columns, lookup, schema) = Table(names, types, columns, lookup, schema, Ref{Dict{String, String}}())

names(t::Table) = getfield(t, :names)
types(t::Table) = getfield(t, :types)
columns(t::Table) = getfield(t, :columns)
lookup(t::Table) = getfield(t, :lookup)
schema(t::Table) = getfield(t, :schema)
getmetadata(t::Table) = isdefined(getfield(t, :metadata), :x) ? getfield(t, :metadata)[] : nothing

Tables.istable(::Table) = true
Tables.columnaccess(::Table) = true
Expand Down Expand Up @@ -272,7 +275,7 @@ function Table(bytes::Vector{UInt8}, off::Integer=1, tlen::Union{Integer, Nothin
end
meta = sch !== nothing ? sch.custom_metadata : nothing
if meta !== nothing
setmetadata!(t, Dict(String(kv.key) => String(kv.value) for kv in meta))
getfield(t, :metadata)[] = Dict(x.key=>x.value for x in meta)
end
return t
end
Expand Down

0 comments on commit 295416d

Please sign in to comment.