From 295416dd2dc52285b57506811512cb442e7d49f2 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Sat, 3 Apr 2021 21:24:10 -0600 Subject: [PATCH] Don't store table metadata globally (#165) * 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. --- src/table.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/table.jl b/src/table.jl index f4e89ef1..e4dd2be2 100644 --- a/src/table.jl +++ b/src/table.jl @@ -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 @@ -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