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

Add Arrow Blobs and fix setMetadata! #1106

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[weakdeps]
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"

[extensions]
DFGPlots = "GraphPlot"
BlobArrow = "Arrow"

[compat]
Arrow = "2.7"
Aqua = "0.8"
Affie marked this conversation as resolved.
Show resolved Hide resolved
Base64 = "1.10"
CSV = "0.10"
Expand Down
23 changes: 23 additions & 0 deletions ext/BlobArrow.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module BlobArrow

using Arrow
using DistributedFactorGraphs
using DistributedFactorGraphs: _MIMETypes

push!(_MIMETypes, MIME("application/vnd.apache.arrow.file") => format"Arrow") # see issue #507

# kwargs: compress = :lz4,
function DFG.packBlob(::Type{format"Arrow"}, data; kwargs...)
io = IOBuffer()
Arrow.write(io, data; kwargs...)
blob = take!(io)
mimetype = findfirst(==(format"Arrow"), _MIMETypes)
return blob, mimetype
end

function DFG.unpackBlob(::Type{format"Arrow"}, blob::Vector{UInt8})
io = IOBuffer(blob)
return Arrow.Table(io)
end

end
Affie marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/DataBlobs/services/BlobPacking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# - application/bson
# - image/jpeg
# - image/png
# - application/vnd.apache.arrow.file

const _MIMETypes = OrderedDict{MIME, DataType}()
push!(_MIMETypes, MIME("application/octet-stream/json") => format"JSON")
Expand Down
3 changes: 2 additions & 1 deletion src/GraphsDFG/entities/GraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ DFG.getAgent(dfg::GraphsDFG) = dfg.agent
DFG.getGraphLabel(dfg::GraphsDFG) = dfg.graphLabel
DFG.getMetadata(dfg::GraphsDFG) = dfg.graphMetadata
function DFG.setMetadata!(dfg::GraphsDFG, metadata::Dict{Symbol, SmallDataTypes})
empty!(dfg.graphMetadata)
# with set old data should be removed, but care is taken to make sure its not the same object
dfg.graphMetadata !== metadata && empty!(dfg.graphMetadata)
return merge!(dfg.graphMetadata, metadata)
end

Expand Down
7 changes: 4 additions & 3 deletions src/services/AbstractDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ $SIGNATURES

Set the metadata of the node.
"""
function setMetadata!(node, data::Dict{Symbol, SmallDataTypes})
empty!(node.metadata)
return merge!(node.metadata, data)
function setMetadata!(node, metadata::Dict{Symbol, SmallDataTypes})
# with set old data should be removed, but care is taken to make sure its not the same object
node.metadata !== metadata && empty!(node.metadata)
return merge!(node.metadata, metadata)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/services/CommonAccessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $SIGNATURES
Set the tags for a DFGNode.
"""
function setTags!(f::DataLevel0, tags::Union{Vector{Symbol}, Set{Symbol}})
empty!(f.tags)
f.tags !== tags && empty!(f.tags)
return union!(f.tags, tags)
end

Expand Down
Loading