Skip to content

Commit f9f4955

Browse files
authored
Merge pull request #1003 from JuliaRobotics/23Q1/maint/hasblob
test hasBlob and rm deprecations and some [Packed]Variable BlobEntry functions
2 parents 2a45bb7 + a5b636a commit f9f4955

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed

src/DataBlobs/services/BlobEntry.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ function getBlobEntry(var::AbstractDFGVariable, key::Symbol)
7979
return var.dataDict[key]
8080
end
8181

82+
function getBlobEntry(var::PackedVariable, key::Symbol)
83+
if !hasBlobEntry(var, key)
84+
throw(KeyError("No dataEntry label $(key) found in variable $(getLabel(var)). Available keys: $(keys(var.dataDict))"))
85+
end
86+
return var.blobEntries[findfirst(x->x.label == key, var.blobEntries)]
87+
end
88+
8289
function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
8390
for (k,v) in var.dataDict
8491
if blobId in [v.originId, v.blobId]
@@ -90,8 +97,6 @@ function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
9097
)
9198
end
9299

93-
@deprecate getBlobEntry(var::AbstractDFGVariable, key::Regex) getBlobEntryFirst(var, key)
94-
95100
"""
96101
$(SIGNATURES)
97102
Finds and returns the first blob entry that matches the regex.
@@ -206,6 +211,9 @@ Does a blob entry (element) exist with `blobLabel`.
206211
"""
207212
hasBlobEntry(var::AbstractDFGVariable, blobLabel::Symbol) = haskey(var.dataDict, blobLabel)
208213

214+
function hasBlobEntry(var::PackedVariable, label::Symbol)
215+
return label in getproperty.(var.blobEntries, :label)
216+
end
209217

210218
"""
211219
$(SIGNATURES)
@@ -273,6 +281,10 @@ function listBlobEntries(var::AbstractDFGVariable)
273281
collect(keys(var.dataDict))
274282
end
275283

284+
function listBlobEntries(var::PackedVariable)
285+
return getproperty.(var.blobEntries, :label)
286+
end
287+
276288
function listBlobEntries(dfg::AbstractDFG, label::Symbol)
277289
# !isVariable(dfg, label) && return nothing
278290
listBlobEntries(getVariable(dfg, label))

src/DataBlobs/services/BlobStores.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ end
278278

279279
hasBlob(store::InMemoryBlobStore, blobId::UUID) = haskey(store.blobs, blobId)
280280

281+
listBlobs(store::InMemoryBlobStore) = collect(keys(store.blobs))
281282

282283
##==============================================================================
283284
## LinkStore Link blobId to a existing local folder

src/Deprecated.jl

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## ================================================================================
2+
## Remove in v0.22
3+
##=================================================================================
4+
5+
@deprecate getBlobEntry(var::AbstractDFGVariable, key::Regex) getBlobEntryFirst(var, key)
16

27
## ================================================================================
38
## Remove in v0.21
@@ -87,23 +92,4 @@ abstract type AbstractBlobEntry end
8792
# return de=>db
8893
# end
8994

90-
## ================================================================================
91-
## Add @deprecate in v0.19, remove after v0.20
92-
##=================================================================================
93-
94-
function Base.convert(::Type{String}, v::VersionNumber)
95-
@warn "Artificial conversion of VersionNumber to String will be deprected in future versions of DFG" maxlog=50
96-
string(v)
97-
end
98-
99-
# TODO ADD DEPRECATION
100-
@deprecate packVariable(::AbstractDFG, v::DFGVariable) packVariable(v)
101-
102-
## ================================================================================
103-
## Deprecate before v0.20
104-
##=================================================================================
105-
106-
export DefaultDFG
107-
108-
const DefaultDFG = GraphsDFG
10995

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export printFactor, printVariable, printNode
291291
export InMemoryBlobStore
292292
export FolderStore
293293
export BlobEntry
294-
export getBlob, addBlob!, updateBlob!, deleteBlob!, listBlobEntries
294+
export getBlob, addBlob!, updateBlob!, deleteBlob!, hasBlob, listBlobEntries
295295
export listBlobs
296296
export BlobEntry
297297
# export copyStore

test/consol_DataEntryBlobTests.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ _,_ = getData(dfg, :x1, "random")
9797
_,_ = getData(dfg, :x1, r"rando")
9898
gde,gdb = getData(dfg, :x1, :random)
9999

100+
@test hasBlob(dfg, ade)
101+
100102
@show gde
101103

102104
@test incrDataLabelSuffix(dfg,:x1,:random) == :random_1
@@ -142,6 +144,11 @@ dde,ddb = deleteData!(dfg, :x1, :random)
142144
ade2 = addData!(dfg, :x2, deepcopy(ade), dataset1)
143145
# ade3,adb3 = updateBlob!(dfg, :x2, deepcopy(ade), dataset1)
144146

147+
@test hasBlob(dfg, ade2)
148+
@test hasBlob(ds, ade2.blobId)
149+
150+
@test length(listBlobs(ds)) == 1
151+
145152
@test ade == ade2# == ade3
146153
# @test adb == adb2# == adb3
147154

@@ -159,18 +166,6 @@ store = TestStore{Int}()
159166
@test_throws ErrorException updateBlob!(store, ade, 1)
160167
@test_throws ErrorException deleteBlob!(store, ade)
161168
@test_throws ErrorException listBlobs(store)
169+
@test_throws ErrorException hasBlob(store, uuid4())
162170

163171

164-
# Dropping use of AbstractDataEntry
165-
# ##==============================================================================
166-
# ## Unimplemented Entry Blob Crud
167-
# ##==============================================================================
168-
# struct NotImplementedDE <: AbstractDataEntry end
169-
170-
# nde = NotImplementedDE()
171-
172-
# @test_throws ErrorException getBlobBlob(dfg, nde)
173-
# @test_throws ErrorException addBlob!(dfg, nde, 1)
174-
# @test_throws ErrorException updateBlob!(dfg, nde, 1)
175-
# @test_throws ErrorException deleteBlob!(dfg, nde)
176-
# @test_throws ErrorException listBlobs(dfg)

test/testBlocks.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,16 @@ function DataEntriesTestBlock!(fg, v2)
943943
@test deleteBlobEntry!(fg, :a, :key2) == de2_update
944944
@test listBlobEntries(v1) == Symbol[]
945945
deleteBlobEntry!(fg, :b, :key2)
946+
947+
# packed variable data entries
948+
pacv = packVariable(v1)
949+
@test addBlobEntry!(pacv, de1) == de1
950+
@test hasBlobEntry(pacv, :key1)
951+
@test deepcopy(de1) == getBlobEntry(pacv, :key1)
952+
@test getBlobEntries(pacv) == [deepcopy(de1)]
953+
@test issetequal(listBlobEntries(pacv), [:key1])
954+
# @test deleteBlobEntry!(pacv, de1) == de1
955+
946956
end
947957

948958
function blobsStoresTestBlock!(fg)

0 commit comments

Comments
 (0)