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

Enhance getGraphBlobEntries filter #1115

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion src/DataBlobs/services/BlobEntry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function getBlobEntry(var::VariableDFG, key::Symbol)
return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)]
end

#TODO maybe rename to getBlobEntryFirst
function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
for (k, v) in var.dataDict
if blobId in [v.originId, v.blobId]
Expand Down Expand Up @@ -121,7 +122,14 @@ function getBlobEntryFirst(var::VariableDFG, key::Regex)
end

function getBlobEntryFirst(dfg::AbstractDFG, label::Symbol, key::Regex)
return getBlobEntryFirst(getVariable(dfg, label), key)
els = listBlobEntries(dfg, label)
firstIdx = findfirst(contains(key), string.(els))
isnothing(firstIdx) && throw(
KeyError(
"No blobEntry with label matching regex $(key) found in variable $(label)",
),
)
return getBlobEntry(dfg, label, els[firstIdx])
end

# TODO Consider autogenerating all methods of the form:
Expand Down
15 changes: 13 additions & 2 deletions src/DataBlobs/services/BlobStores.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ end
##==============================================================================

function getBlob(dfg::AbstractDFG, entry::BlobEntry)
# cannot use entry.blobstore because the blob can be in any one of the blobstores
stores = getBlobStores(dfg)
for (k, store) in stores
storekeys = collect(keys(stores))
# first check the saved blobstore and then fall back to the rest
fidx = findfirst(==(entry.blobstore), storekeys)
if !isnothing(fidx)
skey = storekeys[fidx]
popat!(storekeys, fidx)
pushfirst!(storekeys, skey)
end
for k in storekeys
store = stores[k]
try
blob = getBlob(store, entry)
return blob
Expand Down Expand Up @@ -181,6 +189,9 @@ struct FolderStore{T} <: AbstractBlobStore{T}
folder::String
end

#TODO added in v0.25 to avoid a breaking change in deserialization old DFGs, remove.
StructTypes.StructType(::Type{<:FolderStore}) = StructTypes.OrderedStruct()

function FolderStore(foldername::String; label = :default_folder_store, createfolder = true)
if createfolder && !isdir(foldername)
@info "Folder '$foldername' doesn't exist - creating."
Expand Down
12 changes: 10 additions & 2 deletions src/GraphsDFG/services/GraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,17 @@ function getGraphBlobEntry(fg::GraphsDFG, label::Symbol)
return fg.graphBlobEntries[label]
end

function getGraphBlobEntries(fg::GraphsDFG, startwith::Union{Nothing, String} = nothing)
function getGraphBlobEntries(
fg::GraphsDFG,
filt::Union{Nothing, String, Base.Fix2} = nothing,
)
entries = collect(values(fg.graphBlobEntries))
!isnothing(startwith) && filter!(e -> startswith(string(e.label), startwith), entries)
if !isnothing(filt) && isa(filt, String)
@warn "String filter is deprecated, use startswith(filt_string) instead"
filter!(e -> startswith(string(e.label), filt), entries)
elseif !isnothing(filt)
filter!(e -> filt(string(e.label)), entries)
end
return entries
end

Expand Down
Loading