Skip to content

Commit 467ec8e

Browse files
committed
Merge master into 22Q3/perf/var_point_param
2 parents ba7848f + 77253a9 commit 467ec8e

25 files changed

+799
-352
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
22

33
# v0.20
44

5+
- Throw `KeyError` if `getBlobEntry` is not found, previously was `ErrorException`.
6+
- Change return type on `addData!` convenience wrappers to only return new `BlobEntry`.
7+
- Fix `addBlob!` calls for `FolderStore` and `InMemoryBlobStore` to use `BlobEntry.originId` and not previous bug `entry.id`.
58
- Close long running serialization redo (#590) using only JSON3.jl and StructTypes.jl going forward.
69
- Standardize BlobEntry=>Blob naming of functions, and keeping convenience wrappers `{get,add,update,delete}Data[!]`.
710
- Consolidate to only one `BlobEntry` definition, dropping use of `AbstractBlobEntry`.

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.20.0"
3+
version = "0.20.2"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
7+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
78
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
89
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
910
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

attic/DataBlobs/FileDataEntryBlob.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function addBlob!(dfg::AbstractDFG, entry::BlobEntry, data::Vector{UInt8})
4242
open(entryfilename(entry), "w") do f
4343
JSON.print(f, entry)
4444
end
45-
return getBlob(dfg, entry)::Vector{UInt8}
45+
# FIXME update for entry.blobId vs entry.originId
46+
return UUID(entry.id)
47+
# return getBlob(dfg, entry)::Vector{UInt8}
4648
end
4749
end
4850

@@ -72,7 +74,8 @@ end
7274
function addData!(::Type{BlobEntry}, dfg::AbstractDFG, label::Symbol, key::Symbol, folder::String, blob::Vector{UInt8}, timestamp=now(localzone());
7375
id::UUID = uuid4(), hashfunction = sha256)
7476
fde = BlobEntry(key, id, folder, bytes2hex(hashfunction(blob)), timestamp)
75-
de = addBlobEntry!(dfg, label, fde)
76-
db = addBlob!(dfg, fde, blob)
77-
return de=>db
77+
blobId = addBlob!(dfg, fde, blob) |> UUID
78+
newEntry = BlobEntry(fde; id=blobId, blobId)
79+
de = addBlobEntry!(dfg, label, newEntry)
80+
return de # de=>db
7881
end

docs/extra/CoreAPI.fods

Lines changed: 201 additions & 105 deletions
Large diffs are not rendered by default.

docs/src/variable_factor_serialization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ prior = addFactor!(dfg, [:x0], PriorPose2( MvNormal([10; 10; 1.0/8.0], Matrix(Di
2626

2727
# Now serialize them:
2828
pVariable = packVariable(dfg, x0)
29-
pFactor = packFactor(dfg, prior)
29+
pFactor = packFactor(prior)
3030

3131
# And we can deserialize them
3232
upVariable = unpackVariable(dfg, pVariable)
@@ -60,7 +60,7 @@ for v in getVariables(dfg)
6060
end
6161
# Factors
6262
for f in getFactors(dfg)
63-
fPacked = packFactor(dfg, f)
63+
fPacked = packFactor(f)
6464
io = open("$folder/factors/$(f.label).json", "w")
6565
JSON3.write(io, fPacked)
6666
close(io)

src/DataBlobs/DataBlobs.jl

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ StructTypes.StructType(::Type{BlobEntry}) = StructTypes.UnorderedStruct()
3030
StructTypes.idproperty(::Type{BlobEntry}) = :id
3131
StructTypes.omitempties(::Type{BlobEntry}) = (:id,)
3232

33-
34-
3533
_fixtimezone(cts::NamedTuple) = ZonedDateTime(cts.utc_datetime*"+00")

src/DataBlobs/services/BlobEntry.jl

Lines changed: 86 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function assertHash(de::BlobEntry, db; hashfunction::Function = sha256)
4646
end
4747

4848

49-
function Base.show(io::IO, entry::BlobEntry)
49+
function Base.show(io::IO, ::MIME"text/plain", entry::BlobEntry)
5050
println(io, "_type=BlobEntry {")
5151
println(io, " id: ", entry.id)
5252
println(io, " blobId: ", entry.blobId)
@@ -62,10 +62,6 @@ function Base.show(io::IO, entry::BlobEntry)
6262
println(io, "}")
6363
end
6464

65-
Base.show(io::IO, ::MIME"text/plain", entry::BlobEntry) = show(io, entry)
66-
67-
68-
6965
##==============================================================================
7066
## BlobEntry - CRUD
7167
##==============================================================================
@@ -77,13 +73,15 @@ Get data entry
7773
Also see: [`addBlobEntry`](@ref), [`getBlob`](@ref), [`listBlobEntries`](@ref)
7874
"""
7975
function getBlobEntry(var::AbstractDFGVariable, key::Symbol)
80-
!hasBlobEntry(var, key) && error("No dataEntry label $(key) found in variable $(getLabel(var))")
76+
if !hasBlobEntry(var, key)
77+
throw(KeyError("No dataEntry label $(key) found in variable $(getLabel(var)). Available keys: $(keys(var.dataDict))"))
78+
end
8179
return var.dataDict[key]
8280
end
8381

8482
function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
8583
for (k,v) in var.dataDict
86-
if v.id == blobId
84+
if blobId in [v.originId, v.blobId]
8785
return v
8886
end
8987
end
@@ -92,9 +90,15 @@ function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
9290
)
9391
end
9492

95-
#TODO consider changing this to use `first` as in julia's findfirst - as in findfirstBlobEntry->label::Symbol
96-
# or getBlobEntryFirst, btw this returns a vector in some other places
97-
function getBlobEntry(var::AbstractDFGVariable, key::Regex)
93+
@deprecate getBlobEntry(var::AbstractDFGVariable, key::Regex) getBlobEntryFirst(var, key)
94+
95+
"""
96+
$(SIGNATURES)
97+
Finds and returns the first blob entry that matches the regex.
98+
99+
Also see: [`getBlobEntry`](@ref)
100+
"""
101+
function getBlobEntryFirst(var::AbstractDFGVariable, key::Regex)
98102
for (k,v) in var.dataDict
99103
if occursin(key, string(v.label))
100104
return v
@@ -107,7 +111,7 @@ end
107111

108112
getBlobEntry(var::AbstractDFGVariable, key::AbstractString) = getBlobEntry(var,Regex(key))
109113

110-
114+
#TODO split betweeen getfirstBlobEntry and getBlobEntry
111115
getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID, <:AbstractString, Regex}) = getBlobEntry(getVariable(dfg, label), key)
112116
# getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getBlobEntry(getVariable(dfg, label), key)
113117

@@ -117,16 +121,35 @@ getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID, <:Abstrac
117121
Add Data Entry to a DFG variable
118122
Should be extended if DFG variable is not returned by reference.
119123
120-
Also see: [`getBlobEntry`](@ref), [`addBlob`](@ref), [`mergeBlobEntries!`](@ref)
124+
Also see: [`getBlobEntry`](@ref), [`addBlob!`](@ref), [`mergeBlobEntries!`](@ref)
121125
"""
122-
function addBlobEntry!(var::AbstractDFGVariable, bde::BlobEntry)
123-
haskey(var.dataDict, bde.label) && error("blobEntry $(bde.label) already exists on variable $(getLabel(var))")
124-
var.dataDict[bde.label] = bde
125-
return bde
126+
function addBlobEntry!(
127+
var::AbstractDFGVariable,
128+
entry::BlobEntry;
129+
)
130+
# see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
131+
# blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
132+
# blobSize::Int = (hasfield(BlobEntry, :size) ? entry.size : -1)
133+
haskey(var.dataDict, entry.label) && error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
134+
var.dataDict[entry.label] = entry
135+
return entry
126136
end
127137

128-
function addBlobEntry!(dfg::AbstractDFG, label::Symbol, bde::BlobEntry)
129-
return addBlobEntry!(getVariable(dfg, label), bde)
138+
function addBlobEntry!(
139+
var::PackedVariable,
140+
entry::BlobEntry,
141+
)
142+
entry.label in getproperty.(var.blobEntries,:label) && error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
143+
push!(var.blobEntries, entry)
144+
return entry
145+
end
146+
147+
function addBlobEntry!(
148+
dfg::AbstractDFG,
149+
vLbl::Symbol,
150+
entry::BlobEntry;
151+
)
152+
return addBlobEntry!(getVariable(dfg, vLbl), entry)
130153
end
131154

132155

@@ -186,18 +209,62 @@ hasBlobEntry(var::AbstractDFGVariable, blobLabel::Symbol) = haskey(var.dataDict,
186209

187210
"""
188211
$(SIGNATURES)
189-
Get data entries, Vector{BlobEntry}
212+
213+
Get blob entries, Vector{BlobEntry}
190214
"""
191215
function getBlobEntries(var::AbstractDFGVariable)
192216
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
193217
collect(values(var.dataDict))
194218
end
219+
220+
function getBlobEntries(var::PackedVariable)
221+
var.blobEntries
222+
end
223+
195224
function getBlobEntries(dfg::AbstractDFG, label::Symbol)
196225
# !isVariable(dfg, label) && return nothing
197226
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
198227
getBlobEntries(getVariable(dfg, label))
199228
end
200229

230+
function getBlobEntries(dfg::AbstractDFG, label::Symbol, regex::Regex)
231+
entries = getBlobEntries(dfg, label)
232+
return filter(entries) do e
233+
occursin(regex, string(e.label))
234+
end
235+
end
236+
237+
238+
"""
239+
$(SIGNATURES)
240+
241+
Get all blob entries matching a Regex pattern over variables
242+
243+
Notes
244+
- Use `dropEmpties=true` to not include empty lists in result.
245+
- Use keyword `varList` for which variables to search through.
246+
"""
247+
function getBlobEntriesVariables(
248+
dfg::AbstractDFG,
249+
bLblPattern::Regex;
250+
varList::AbstractVector{Symbol} = sort(listVariables(dfg); lt=natural_lt),
251+
dropEmpties::Bool = false
252+
)
253+
RETLIST = Vector{Vector{BlobEntry}}()
254+
@showprogress "Get entries matching $bLblPattern" for vl in varList
255+
bes = filter(
256+
s->occursin(bLblPattern,string(s.label)),
257+
listBlobEntries(dfg,vl)
258+
)
259+
# only push to list if there are entries on this variable
260+
(!dropEmpties || 0 < length(bes)) ? nothing : continue
261+
push!(RETLIST, bes)
262+
end
263+
264+
return RETLIST
265+
end
266+
267+
201268
"""
202269
$(SIGNATURES)
203270
List the blob entries associated with a particular variable.

0 commit comments

Comments
 (0)