Skip to content

Commit b09697f

Browse files
committed
WIP #403 - rename Elements->Blob
1 parent e2ddf93 commit b09697f

14 files changed

+367
-156
lines changed

src/BigData/BigData.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ include("services/FileDataStore.jl")
1010

1111
export AbstractDataStore
1212

13-
export AbstractBigDataEntry, GeneralBigDataEntry, MongodbBigDataEntry, FileBigDataEntry
13+
export AbstractBigDataEntry, GeneralDataEntry, MongodbDataEntry, FileDataEntry
1414
export InMemoryDataStore, FileDataStore
1515

16-
export getBigData, addBigData!, updateBigData!, deleteBigData!, listStoreEntries
16+
export getData, addData!, updateData!, deleteData!, listStoreEntries
17+
export getDataBlob, addDataBlob!, updateDataBlob!, deleteDataBlob!, listDataBlobs
1718
export copyStore

src/BigData/entities/AbstractBigDataEntries.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
GeneralBigDataEntry is a generic multipurpose data entry that creates a unique
44
reproducible key using userId_robotId_sessionId_variableId_key.
55
"""
6-
mutable struct GeneralBigDataEntry <: AbstractBigDataEntry
6+
mutable struct GeneralDataEntry <: AbstractBigDataEntry
77
key::Symbol
88
storeKey::Symbol # Could swap this to string, but using it as an index later, so better as a symbol I believe.
99
createdTimestamp::DateTime
@@ -21,32 +21,39 @@ function _uniqueKey(dfg::G, v::V, key::Symbol)::Symbol where {G <: AbstractDFG,
2121
return Symbol(key)
2222
end
2323

24-
GeneralBigDataEntry(key::Symbol, storeKey::Symbol;
24+
25+
GeneralDataEntry(key::Symbol, storeKey::Symbol;
2526
mimeType::String="application/octet-stream") =
26-
GeneralBigDataEntry(key, storeKey, now(), now(), mimeType)
27+
GeneralDataEntry(key, storeKey, now(), now(), mimeType)
2728

28-
function GeneralBigDataEntry(dfg::G, var::V, key::Symbol;
29+
function GeneralDataEntry(dfg::G, var::V, key::Symbol;
2930
mimeType::String="application/octet-stream") where {G <: AbstractDFG, V <: AbstractDFGVariable}
30-
return GeneralBigDataEntry(key, _uniqueKey(dfg, var, key), mimeType=mimeType)
31+
return GeneralDataEntry(key, _uniqueKey(dfg, var, key), mimeType=mimeType)
3132
end
3233

34+
@deprecate GeneralBigDataEntry(args...; kwargs...) GeneralDataEntry(args...; kwargs...)
35+
3336
"""
3437
$(TYPEDEF)
3538
BigDataEntry in MongoDB.
3639
"""
37-
struct MongodbBigDataEntry <: AbstractBigDataEntry
40+
struct MongodbDataEntry <: AbstractBigDataEntry
3841
key::Symbol
3942
oid::NTuple{12, UInt8} #mongodb object id
4043
#maybe other fields such as:
4144
#flags::Bool ready, valid, locked, permissions
42-
#MIMEType::Symbol
45+
#MIMEType::String
4346
end
4447

48+
@deprecate MongodbBigDataEntry(args...) MongodbDataEntry(args...)
49+
4550
"""
4651
$(TYPEDEF)
4752
BigDataEntry in a file.
4853
"""
49-
struct FileBigDataEntry <: AbstractBigDataEntry
54+
struct FileDataEntry <: AbstractBigDataEntry
5055
key::Symbol
5156
filename::String
5257
end
58+
59+
@deprecate FileBigDataEntry(args...) FileDataEntry(args...)

src/BigData/entities/InMemoryDataStore.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ end
2020
Create an in-memory store using binary data (UInt8) as a type.
2121
"""
2222
function InMemoryDataStore()
23-
return InMemoryDataStore{Vector{UInt8}, GeneralBigDataEntry}()
23+
return InMemoryDataStore{Vector{UInt8}, GeneralDataEntry}()
2424
end
Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
import Base: ==
22

3-
function ==(a::GeneralBigDataEntry, b::GeneralBigDataEntry)
3+
function ==(a::GeneralDataEntry, b::GeneralDataEntry)
44
return a.key == b.key &&
55
a.storeKey == b.storeKey &&
66
a.mimeType == b.mimeType &&
77
Dates.value(a.createdTimestamp - b.createdTimestamp) < 1000 &&
88
Dates.value(a.lastUpdatedTimestamp - b.lastUpdatedTimestamp) < 1000 #1 second
99
end
1010

11-
function ==(a::MongodbBigDataEntry, b::MongodbBigDataEntry)
11+
function ==(a::MongodbDataEntry, b::MongodbDataEntry)
1212
return a.key == b.key && a.oid == b.oid
1313
end
1414

15-
function ==(a::FileBigDataEntry, b::FileBigDataEntry)
15+
function ==(a::FileDataEntry, b::FileDataEntry)
1616
return a.key == b.key && a.filename == b.filename
1717
end
1818

1919
"""
2020
$(SIGNATURES)
2121
Add Big Data Entry to a DFG variable
2222
"""
23-
function addBigDataEntry!(var::AbstractDFGVariable, bde::AbstractBigDataEntry)
23+
function addDataEntry!(var::AbstractDFGVariable, bde::AbstractBigDataEntry)
2424
haskey(var.bigData,bde.key) && error("BigData entry $(bde.key) already exists in variable")
2525
var.bigData[bde.key] = bde
2626
return bde
2727
end
2828

29+
2930
"""
3031
$(SIGNATURES)
3132
Add Big Data Entry to distributed factor graph.
3233
Should be extended if DFG variable is not returned by reference.
3334
"""
34-
function addBigDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractBigDataEntry)
35+
function addDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractBigDataEntry)
3536
return addBigDataEntry!(getVariable(dfg, label), bde)
3637
end
3738

38-
addDataEntry!(x...) = addBigDataEntry!(x...)
39+
@deprecate addBigDataEntry!(args...) addDataEntry!(args...)
3940

4041
"""
4142
$(SIGNATURES)
@@ -50,22 +51,22 @@ Related
5051
5152
addData!, getDataEntryElement, fetchData
5253
"""
53-
function addDataEntry!(dfg::AbstractDFG,
54-
lbl::Symbol,
55-
datastore::Union{FileDataStore, InMemoryDataStore},
56-
descr::Symbol,
57-
mimeType::AbstractString,
58-
data::Vector{UInt8} )
54+
function addData!(dfg::AbstractDFG,
55+
lbl::Symbol,
56+
datastore::Union{FileDataStore, InMemoryDataStore},
57+
descr::Symbol,
58+
mimeType::AbstractString,
59+
data::Vector{UInt8} )
5960
#
6061
node = isVariable(dfg, lbl) ? getVariable(dfg, lbl) : getFactor(dfg, lbl)
6162
# Make a big data entry in the graph - use JSON2 to just write this
62-
entry = GeneralBigDataEntry(dfg, node, descr, mimeType=mimeType)
63+
entry = GeneralDataEntry(dfg, node, descr, mimeType=mimeType)
6364
# Set it in the store
64-
addBigData!(datastore, entry, data)
65+
addDataBlob!(datastore, entry, data)
6566
# Add the entry to the graph
66-
addBigDataEntry!(node, entry)
67+
addDataEntry!(node, entry)
6768
end
68-
const addData! = addDataEntry!
69+
# const addDataEntry! = addData!
6970

7071
"""
7172
$SIGNATURES
@@ -79,15 +80,17 @@ const hasBigDataEntry = hasDataEntry
7980
$(SIGNATURES)
8081
Get big data entry
8182
"""
82-
function getBigDataEntry(var::AbstractDFGVariable, key::Symbol)
83+
function getDataEntry(var::AbstractDFGVariable, key::Symbol)
8384
!hasDataEntry(var, key) && (error("BigData entry $(key) does not exist in variable"); return nothing)
8485
return var.bigData[key]
8586
end
8687

87-
function getBigDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol)
88+
function getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol)
8889
return getBigDataEntry(getVariable(dfg, label), key)
8990
end
9091

92+
@deprecate getBigDataEntry(args...) getDataEntry(args...)
93+
9194
"""
9295
$SIGNATURES
9396
Get both the entry and raw data element from datastore returning as a tuple.
@@ -125,24 +128,26 @@ Related
125128
126129
addDataEntry!, addData!, fetchData, fetchDataEntryElement
127130
"""
128-
function getDataEntryElement(dfg::AbstractDFG,
129-
dfglabel::Symbol,
130-
datastore::Union{FileDataStore, InMemoryDataStore},
131-
datalabel::Symbol)
131+
function getDataEntryBlob(dfg::AbstractDFG,
132+
dfglabel::Symbol,
133+
datastore::Union{FileDataStore, InMemoryDataStore},
134+
datalabel::Symbol)
132135
#
133136
vari = getVariable(dfg, dfglabel)
134137
if !hasDataEntry(vari, datalabel)
135-
@error "missing data entry $datalabel in $dfglabel"
136-
return nothing, nothing
138+
# current standards is to fail hard
139+
error("missing data entry $datalabel in $dfglabel")
140+
# return nothing, nothing
137141
end
138-
entry = getBigDataEntry(vari, datalabel)
139-
element = getBigData(datastore, entry)
142+
entry = getDataEntry(vari, datalabel)
143+
element = getDataBlob(datastore, entry)
140144
return entry, element
141145
end
142-
const fetchDataEntryElement = getDataEntryElement
143-
const fetchData = getDataEntryElement
144-
146+
const fetchDataEntryElement = getDataEntryBlob
147+
const fetchData = getDataEntryBlob
145148

149+
#
150+
@deprecate getDataEntryElement(args...) getDataEntryBlob(args...)
146151

147152
"""
148153
$(SIGNATURES)
@@ -151,16 +156,18 @@ Update big data entry
151156
DevNote
152157
- DF, unclear if `update` verb is applicable in this case, see #404
153158
"""
154-
function updateBigDataEntry!(var::AbstractDFGVariable, bde::AbstractBigDataEntry)
159+
function updateDataEntry!(var::AbstractDFGVariable, bde::AbstractBigDataEntry)
155160
!haskey(var.bigData,bde.key) && (@warn "$(bde.key) does not exist in variable, adding")
156161
var.bigData[bde.key] = bde
157162
return bde
158163
end
159-
function updateBigDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractBigDataEntry)
164+
function updateDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractBigDataEntry)
160165
# !isVariable(dfg, label) && return nothing
161-
return updateBigDataEntry!(getVariable(dfg, label), bde)
166+
return updateDataEntry!(getVariable(dfg, label), bde)
162167
end
163168

169+
@deprecate updateBigDataEntry!(args...) updateDataEntry!(args...)
170+
164171
"""
165172
$(SIGNATURES)
166173
Delete big data entry from the factor graph.
@@ -169,46 +176,52 @@ Note this doesn't remove it from any data stores.
169176
Notes:
170177
- users responsibility to delete big data in db before deleting entry
171178
"""
172-
function deleteBigDataEntry!(var::AbstractDFGVariable, key::Symbol)
173-
bde = getBigDataEntry(var, key)
179+
function deleteDataEntry!(var::AbstractDFGVariable, key::Symbol)
180+
bde = getDataEntry(var, key)
174181
bde == nothing && return nothing
175182
delete!(var.bigData, key)
176183
return var
177184
end
178-
function deleteBigDataEntry!(dfg::AbstractDFG, label::Symbol, key::Symbol)
185+
function deleteDataEntry!(dfg::AbstractDFG, label::Symbol, key::Symbol)
179186
#users responsibility to delete big data in db before deleting entry
180187
!isVariable(dfg, label) && return nothing
181-
return deleteBigDataEntry!(getVariable(dfg, label), key)
188+
return deleteDataEntry!(getVariable(dfg, label), key)
182189
end
183190

184-
function deleteBigDataEntry!(var::AbstractDFGVariable, entry::AbstractBigDataEntry)
191+
function deleteDataEntry!(var::AbstractDFGVariable, entry::AbstractBigDataEntry)
185192
#users responsibility to delete big data in db before deleting entry
186-
return deleteBigDataEntry!(var, entry.key)
193+
return deleteDataEntry!(var, entry.key)
187194
end
188195

196+
@deprecate deleteBigDataEntry!(args...) deleteDataEntry!(args...)
197+
189198
"""
190199
$(SIGNATURES)
191200
Get big data entries, Vector{AbstractBigDataEntry}
192201
"""
193-
function getBigDataEntries(var::AbstractDFGVariable)
202+
function getDataEntries(var::AbstractDFGVariable)
194203
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,AbstractBigDataEntry}}?
195204
collect(values(var.bigData))
196205
end
197-
function getBigDataEntries(dfg::AbstractDFG, label::Symbol)
206+
function getDataEntries(dfg::AbstractDFG, label::Symbol)
198207
!isVariable(dfg, label) && return nothing
199208
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,AbstractBigDataEntry}}?
200-
getBigDataEntries(getVariable(dfg, label))
209+
getDataEntries(getVariable(dfg, label))
201210
end
202211

212+
@deprecate getBigDataEntries(args...) getDataEntries(args...)
213+
203214

204215
"""
205216
$(SIGNATURES)
206-
getBigDataKeys
217+
listDataEntries
207218
"""
208-
function getBigDataKeys(var::AbstractDFGVariable)
219+
function listDataEntries(var::AbstractDFGVariable)
209220
collect(keys(var.bigData))
210221
end
211-
function getBigDataKeys(dfg::AbstractDFG, label::Symbol)
222+
function listDataEntries(dfg::AbstractDFG, label::Symbol)
212223
!isVariable(dfg, label) && return nothing
213-
getBigDataKeys(getVariable(dfg, label))
224+
listDataEntries(getVariable(dfg, label))
214225
end
226+
227+
@deprecate getBigDataKeys(args...) listDataEntries(args...)

src/BigData/services/AbstractDataStore.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@
22
$(SIGNATURES)
33
Get the data for the specified entry, returns the data or Nothing.
44
"""
5-
function getBigData(store::D, entry::E)::Union{Nothing, T} where {T, D <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
6-
error("$(typeof(store)) doesn't override 'getData'.")
5+
function getDataBlob(store::D, entry::E)::Union{Nothing, T} where {T, D <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
6+
error("$(typeof(store)) doesn't override 'getDataBlob'.")
77
end
88

99
"""
1010
$(SIGNATURES)
1111
Adds the data to the store with the given entry. The function will warn if the entry already
1212
exists and will overwrite it.
1313
"""
14-
function addBigData!(store::D, entry::E, data::T)::Union{Nothing, T} where {T, D <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
15-
error("$(typeof(store)) doesn't override 'addData!'.")
14+
function addDataBlob!(store::D, entry::E, data::T)::Union{Nothing, T} where {T, D <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
15+
error("$(typeof(store)) doesn't override 'addDataBlob!'.")
1616
end
1717

1818
"""
1919
$(SIGNATURES)
2020
Update the data in the store. The function will error and return nothing if
2121
the entry does not exist.
2222
"""
23-
function updateBigData!(store::D, entry::E, data::T)::Union{Nothing, T} where {T, D <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
24-
error("$(typeof(store)) doesn't override 'updateData!'.")
23+
function updateDataBlob!(store::D, entry::E, data::T)::Union{Nothing, T} where {T, D <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
24+
error("$(typeof(store)) doesn't override 'updateDataBlob!'.")
2525
end
2626

2727
"""
2828
$(SIGNATURES)
2929
Delete the data in the store for the given entry. The function will error and return nothing if
3030
the entry does not exist.
3131
"""
32-
function deleteBigData!(store::D, entry::E)::Union{Nothing, T} where {T, D <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
33-
error("$(typeof(store)) doesn't override 'deleteData!'.")
32+
function deleteDataBlob!(store::D, entry::E)::Union{Nothing, T} where {T, D <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
33+
error("$(typeof(store)) doesn't override 'deleteDataBlob!'.")
3434
end
3535

3636
"""
3737
$(SIGNATURES)
3838
List all entries in the data store.
3939
"""
40-
function listStoreEntries(store::D)::Vector{E} where {D <: AbstractDataStore, E <: AbstractBigDataEntry}
41-
error("$(typeof(store)) doesn't override 'listEntries'.")
40+
function listDataBlobs(store::D) where D <: AbstractDataStore
41+
error("$(typeof(store)) doesn't override 'listDataBlobs'.")
4242
end
4343

4444
"""
@@ -49,13 +49,13 @@ Returns the list of copied entries.
4949
"""
5050
function copyStore(sourceStore::D1, destStore::D2; sourceEntries=listEntries(sourceStore))::Vector{E} where {T, D1 <: AbstractDataStore{T}, D2 <: AbstractDataStore{T}, E <: AbstractBigDataEntry}
5151
# Quick check
52-
destEntries = listStoreEntries(destStore)
52+
destEntries = listDataBlobs(destStore)
5353
typeof(sourceEntries) != typeof(destEntries) && error("Can't copy stores, source has entries of type $(typeof(sourceEntries)), destination has entries of type $(typeof(destEntries)).")
5454
# Same source/destination check
5555
sourceStore == destStore && error("Can't specify same store for source and destination.")
5656
# Otherwise, continue
5757
for sourceEntry in sourceEntries
58-
addBigData!(destStore, deepcopy(sourceEntry), getBigData(sourceStore, sourceEntry))
58+
addDataBlob!(destStore, deepcopy(sourceEntry), getDataBlob(sourceStore, sourceEntry))
5959
end
6060
return sourceEntries
6161
end

0 commit comments

Comments
 (0)