Skip to content

Commit c0d6f46

Browse files
authored
port from #4283 (#4286)
1 parent 9783037 commit c0d6f46

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

apis/python/src/tiledbsoma/_soma_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _set_element(
149149
uri=uri,
150150
uri_type=relative_type,
151151
name=key,
152-
soma_type=clib_collection.type,
152+
soma_type=soma_object.soma_type,
153153
)
154154
self._contents[key] = _CachedElement(
155155
entry=_tdb_handles.GroupEntry(soma_object.uri, soma_object._wrapper_type),

apis/python/tests/test_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_collection_mapping(soma_object, tmp_path):
170170
assert list(k for k in c) == list(c.keys())
171171
assert len(c) == 1
172172
assert [k for k in c] == ["mumble"]
173-
assert c.members() == {"mumble": (soma_object.uri, "SOMACollection")}
173+
assert c.members() == {"mumble": (soma_object.uri, soma_object.soma_type)}
174174

175175
# TEMPORARY: This should no longer raise an error once TileDB supports
176176
# replacing an existing group member.

libtiledbsoma/src/soma/soma_group.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,12 @@ bool SOMAGroup::has(const std::string& name) {
192192
}
193193

194194
void SOMAGroup::set(const std::string& uri, URIType uri_type, const std::string& name, const std::string& soma_type) {
195+
auto tiledb_type = this->tiledb_type_from_soma_type(soma_type);
195196
bool relative = uri_type == URIType::relative;
196197
if (uri_type == URIType::automatic) {
197198
relative = !((uri.find("://") != std::string::npos) || (uri.find("/") == 0));
198199
}
199-
group_->add_member(uri, relative, name);
200+
group_->add_member(uri, relative, name, tiledb_type);
200201
members_map_[name] = SOMAGroupEntry(uri, soma_type);
201202
}
202203

libtiledbsoma/src/soma/soma_group.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class SOMAGroup : public SOMAObject {
183183
* @param uri of member to add
184184
* @param uri_type whether the given URI is automatic (default), absolute,
185185
* or relative
186-
* @param name of member
186+
* @param soma_type the soma_type of the member
187187
*/
188188
void set(const std::string& uri, URIType uri_type, const std::string& name, const std::string& soma_type);
189189

libtiledbsoma/src/soma/soma_object.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,25 @@ bool SOMAObject::check_type(std::string expected_type) {
145145
return soma_object_type == expected_type;
146146
};
147147

148+
tiledb_object_t SOMAObject::tiledb_type_from_soma_type(const std::string& soma_type) {
149+
const std::map<std::string, tiledb_object_t> typeMap = {
150+
{"SOMAArray", tiledb_object_t::TILEDB_ARRAY},
151+
{"SOMACollection", tiledb_object_t::TILEDB_GROUP},
152+
{"SOMADataFrame", tiledb_object_t::TILEDB_ARRAY},
153+
{"SOMADenseNDArray", tiledb_object_t::TILEDB_ARRAY},
154+
{"SOMAExperiment", tiledb_object_t::TILEDB_GROUP},
155+
{"SOMAGeometryDataFrame", tiledb_object_t::TILEDB_ARRAY},
156+
{"SOMAGroup", tiledb_object_t::TILEDB_GROUP},
157+
{"SOMAMeasurement", tiledb_object_t::TILEDB_GROUP},
158+
{"SOMAMultiscaleImage", tiledb_object_t::TILEDB_GROUP},
159+
{"SOMAPointCloudDataFrame", tiledb_object_t::TILEDB_ARRAY},
160+
{"SOMAScene", tiledb_object_t::TILEDB_GROUP},
161+
{"SOMASparseNDArray", tiledb_object_t::TILEDB_ARRAY},
162+
};
163+
const std::map<std::string, tiledb_object_t>::const_iterator iTileDBType = typeMap.find(soma_type);
164+
if (iTileDBType == typeMap.end())
165+
return tiledb_object_t::TILEDB_INVALID;
166+
return iTileDBType->second;
167+
};
168+
148169
} // namespace tiledbsoma

libtiledbsoma/src/soma/soma_object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ class SOMAObject {
167167
* must be opened in READ mode, otherwise the function will error out.
168168
*/
169169
virtual uint64_t metadata_num() const = 0;
170+
171+
/**
172+
* @brief Given a soma_type, return the underlying TileDB type.
173+
*/
174+
static tiledb_object_t tiledb_type_from_soma_type(const std::string& soma_type);
170175
};
171176
} // namespace tiledbsoma
172177

0 commit comments

Comments
 (0)