Skip to content

Commit 2f7de57

Browse files
authored
Merge pull request #519 from JuliaRobotics/maint/20Q2/bigdata_blob
BigData rename
2 parents 5005d33 + 97c0be3 commit 2f7de57

24 files changed

+524
-261
lines changed

src/BigData/BigData.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
include("entities/AbstractDataStore.jl")
2+
#TODO Rename to AbstractDataEntries
23
include("entities/AbstractBigDataEntries.jl")
34
include("entities/InMemoryDataStore.jl")
45
include("entities/FileDataStore.jl")
56

67
include("services/AbstractDataStore.jl")
8+
#TODO Rename to AbstractDataEntries
79
include("services/AbstractBigDataEntries.jl")
810
include("services/InMemoryDataStore.jl")
911
include("services/FileDataStore.jl")
1012

1113
export AbstractDataStore
1214

13-
export AbstractBigDataEntry, GeneralBigDataEntry, MongodbBigDataEntry, FileBigDataEntry
15+
export AbstractDataEntry, GeneralDataEntry, MongodbDataEntry, FileDataEntry
1416
export InMemoryDataStore, FileDataStore
1517

16-
export getBigData, addBigData!, updateBigData!, deleteBigData!, listStoreEntries
18+
export getData, addData!, updateData!, deleteData!, listStoreEntries
19+
export getDataBlob, addDataBlob!, updateDataBlob!, deleteDataBlob!, listDataBlobs
1720
export copyStore
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
22
$(TYPEDEF)
3-
GeneralBigDataEntry is a generic multipurpose data entry that creates a unique
3+
GeneralDataEntry 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 <: AbstractDataEntry
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,34 @@ 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

3334
"""
3435
$(TYPEDEF)
35-
BigDataEntry in MongoDB.
36+
Data Entry in MongoDB.
3637
"""
37-
struct MongodbBigDataEntry <: AbstractBigDataEntry
38+
struct MongodbDataEntry <: AbstractDataEntry
3839
key::Symbol
3940
oid::NTuple{12, UInt8} #mongodb object id
4041
#maybe other fields such as:
4142
#flags::Bool ready, valid, locked, permissions
42-
#MIMEType::Symbol
43+
#MIMEType::String
4344
end
4445

46+
4547
"""
4648
$(TYPEDEF)
47-
BigDataEntry in a file.
49+
Data Entry in a file.
4850
"""
49-
struct FileBigDataEntry <: AbstractBigDataEntry
51+
struct FileDataEntry <: AbstractDataEntry
5052
key::Symbol
5153
filename::String
5254
end

src/BigData/entities/InMemoryDataStore.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$(TYPEDEF)
33
Simple in-memory data store with a specified data type and a specified key type.
44
"""
5-
struct InMemoryDataStore{T, E <: AbstractBigDataEntry} <: AbstractDataStore{T}
5+
struct InMemoryDataStore{T, E <: AbstractDataEntry} <: AbstractDataStore{T}
66
data::Dict{Symbol, T}
77
entries::Dict{Symbol, E}
88
end
@@ -11,7 +11,7 @@ end
1111
$(SIGNATURES)
1212
Create an in-memory store using a specific data type.
1313
"""
14-
function InMemoryDataStore{T, E}() where {T, E <: AbstractBigDataEntry}
14+
function InMemoryDataStore{T, E}() where {T, E <: AbstractDataEntry}
1515
return InMemoryDataStore{T, E}(Dict{Symbol, T}(), Dict{Symbol, E}())
1616
end
1717

@@ -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: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
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)
24-
haskey(var.bigData,bde.key) && error("BigData entry $(bde.key) already exists in variable")
25-
var.bigData[bde.key] = bde
23+
function addDataEntry!(var::AbstractDFGVariable, bde::AbstractDataEntry)
24+
haskey(var.dataDict, bde.key) && error("Data entry $(bde.key) already exists in variable")
25+
var.dataDict[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-
return addBigDataEntry!(getVariable(dfg, label), bde)
35+
function addDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractDataEntry)
36+
return addDataEntry!(getVariable(dfg, label), bde)
3637
end
3738

38-
addDataEntry!(x...) = addBigDataEntry!(x...)
3939

4040
"""
4141
$(SIGNATURES)
@@ -50,42 +50,41 @@ Related
5050
5151
addData!, getDataEntryElement, fetchData
5252
"""
53-
function addDataEntry!(dfg::AbstractDFG,
54-
lbl::Symbol,
55-
datastore::Union{FileDataStore, InMemoryDataStore},
56-
descr::Symbol,
57-
mimeType::AbstractString,
58-
data::Vector{UInt8} )
53+
function addData!(dfg::AbstractDFG,
54+
lbl::Symbol,
55+
datastore::Union{FileDataStore, InMemoryDataStore},
56+
descr::Symbol,
57+
mimeType::AbstractString,
58+
data::Vector{UInt8} )
5959
#
6060
node = isVariable(dfg, lbl) ? getVariable(dfg, lbl) : getFactor(dfg, lbl)
6161
# Make a big data entry in the graph - use JSON2 to just write this
62-
entry = GeneralBigDataEntry(dfg, node, descr, mimeType=mimeType)
62+
entry = GeneralDataEntry(dfg, node, descr, mimeType=mimeType)
6363
# Set it in the store
64-
addBigData!(datastore, entry, data)
64+
addDataBlob!(datastore, entry, data)
6565
# Add the entry to the graph
66-
addBigDataEntry!(node, entry)
66+
addDataEntry!(node, entry)
6767
end
68-
const addData! = addDataEntry!
68+
# const addDataEntry! = addData!
6969

7070
"""
7171
$SIGNATURES
7272
7373
Does a data entry (element) exist at `key`.
7474
"""
75-
hasDataEntry(var::DFGVariable, key::Symbol) = haskey(var.bigData, key)
76-
const hasBigDataEntry = hasDataEntry
75+
hasDataEntry(var::DFGVariable, key::Symbol) = haskey(var.dataDict, key)
7776

7877
"""
7978
$(SIGNATURES)
8079
Get big data entry
8180
"""
82-
function getBigDataEntry(var::AbstractDFGVariable, key::Symbol)
83-
!hasDataEntry(var, key) && (error("BigData entry $(key) does not exist in variable"); return nothing)
84-
return var.bigData[key]
81+
function getDataEntry(var::AbstractDFGVariable, key::Symbol)
82+
!hasDataEntry(var, key) && (error("Data entry $(key) does not exist in variable"); return nothing)
83+
return var.dataDict[key]
8584
end
8685

87-
function getBigDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol)
88-
return getBigDataEntry(getVariable(dfg, label), key)
86+
function getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol)
87+
return getDataEntry(getVariable(dfg, label), key)
8988
end
9089

9190
"""
@@ -125,24 +124,25 @@ Related
125124
126125
addDataEntry!, addData!, fetchData, fetchDataEntryElement
127126
"""
128-
function getDataEntryElement(dfg::AbstractDFG,
129-
dfglabel::Symbol,
130-
datastore::Union{FileDataStore, InMemoryDataStore},
131-
datalabel::Symbol)
127+
function getDataEntryBlob(dfg::AbstractDFG,
128+
dfglabel::Symbol,
129+
datastore::Union{FileDataStore, InMemoryDataStore},
130+
datalabel::Symbol)
132131
#
133132
vari = getVariable(dfg, dfglabel)
134133
if !hasDataEntry(vari, datalabel)
135-
@error "missing data entry $datalabel in $dfglabel"
136-
return nothing, nothing
134+
# current standards is to fail hard
135+
error("missing data entry $datalabel in $dfglabel")
136+
# return nothing, nothing
137137
end
138-
entry = getBigDataEntry(vari, datalabel)
139-
element = getBigData(datastore, entry)
138+
entry = getDataEntry(vari, datalabel)
139+
element = getDataBlob(datastore, entry)
140140
return entry, element
141141
end
142-
const fetchDataEntryElement = getDataEntryElement
143-
const fetchData = getDataEntryElement
144-
142+
const fetchDataEntryElement = getDataEntryBlob
143+
const fetchData = getDataEntryBlob
145144

145+
#
146146

147147
"""
148148
$(SIGNATURES)
@@ -151,14 +151,14 @@ Update big data entry
151151
DevNote
152152
- DF, unclear if `update` verb is applicable in this case, see #404
153153
"""
154-
function updateBigDataEntry!(var::AbstractDFGVariable, bde::AbstractBigDataEntry)
155-
!haskey(var.bigData,bde.key) && (@warn "$(bde.key) does not exist in variable, adding")
156-
var.bigData[bde.key] = bde
154+
function updateDataEntry!(var::AbstractDFGVariable, bde::AbstractDataEntry)
155+
!haskey(var.dataDict, bde.key) && (@warn "$(bde.key) does not exist in variable, adding")
156+
var.dataDict[bde.key] = bde
157157
return bde
158158
end
159-
function updateBigDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractBigDataEntry)
159+
function updateDataEntry!(dfg::AbstractDFG, label::Symbol, bde::AbstractDataEntry)
160160
# !isVariable(dfg, label) && return nothing
161-
return updateBigDataEntry!(getVariable(dfg, label), bde)
161+
return updateDataEntry!(getVariable(dfg, label), bde)
162162
end
163163

164164
"""
@@ -169,46 +169,47 @@ Note this doesn't remove it from any data stores.
169169
Notes:
170170
- users responsibility to delete big data in db before deleting entry
171171
"""
172-
function deleteBigDataEntry!(var::AbstractDFGVariable, key::Symbol)
173-
bde = getBigDataEntry(var, key)
172+
function deleteDataEntry!(var::AbstractDFGVariable, key::Symbol)
173+
bde = getDataEntry(var, key)
174174
bde == nothing && return nothing
175-
delete!(var.bigData, key)
175+
delete!(var.dataDict, key)
176176
return var
177177
end
178-
function deleteBigDataEntry!(dfg::AbstractDFG, label::Symbol, key::Symbol)
178+
function deleteDataEntry!(dfg::AbstractDFG, label::Symbol, key::Symbol)
179179
#users responsibility to delete big data in db before deleting entry
180180
!isVariable(dfg, label) && return nothing
181-
return deleteBigDataEntry!(getVariable(dfg, label), key)
181+
return deleteDataEntry!(getVariable(dfg, label), key)
182182
end
183183

184-
function deleteBigDataEntry!(var::AbstractDFGVariable, entry::AbstractBigDataEntry)
184+
function deleteDataEntry!(var::AbstractDFGVariable, entry::AbstractDataEntry)
185185
#users responsibility to delete big data in db before deleting entry
186-
return deleteBigDataEntry!(var, entry.key)
186+
return deleteDataEntry!(var, entry.key)
187187
end
188188

189189
"""
190190
$(SIGNATURES)
191-
Get big data entries, Vector{AbstractBigDataEntry}
191+
Get big data entries, Vector{AbstractDataEntry}
192192
"""
193-
function getBigDataEntries(var::AbstractDFGVariable)
194-
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,AbstractBigDataEntry}}?
195-
collect(values(var.bigData))
193+
function getDataEntries(var::AbstractDFGVariable)
194+
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,AbstractDataEntry}}?
195+
collect(values(var.dataDict))
196196
end
197-
function getBigDataEntries(dfg::AbstractDFG, label::Symbol)
197+
function getDataEntries(dfg::AbstractDFG, label::Symbol)
198198
!isVariable(dfg, label) && return nothing
199-
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,AbstractBigDataEntry}}?
200-
getBigDataEntries(getVariable(dfg, label))
199+
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,AbstractDataEntry}}?
200+
getDataEntries(getVariable(dfg, label))
201201
end
202202

203203

204204
"""
205205
$(SIGNATURES)
206-
getBigDataKeys
206+
listDataEntries
207207
"""
208-
function getBigDataKeys(var::AbstractDFGVariable)
209-
collect(keys(var.bigData))
208+
function listDataEntries(var::AbstractDFGVariable)
209+
collect(keys(var.dataDict))
210210
end
211-
function getBigDataKeys(dfg::AbstractDFG, label::Symbol)
211+
212+
function listDataEntries(dfg::AbstractDFG, label::Symbol)
212213
!isVariable(dfg, label) && return nothing
213-
getBigDataKeys(getVariable(dfg, label))
214+
listDataEntries(getVariable(dfg, label))
214215
end

0 commit comments

Comments
 (0)