MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / scan_sparse

Method scan_sparse

nodedb/src/data/executor/scan_normalize.rs:220–259  ·  view source on GitHub ↗

Scan sparse/document engine → standard msgpack. Handles both schemaless (msgpack) and strict (Binary Tuple) formats.

(
        &self,
        tid: u64,
        collection: &str,
        limit: usize,
    )

Source from the content-addressed store, hash-verified

218 /// Scan sparse/document engine → standard msgpack.
219 /// Handles both schemaless (msgpack) and strict (Binary Tuple) formats.
220 pub(super) fn scan_sparse(
221 &self,
222 tid: u64,
223 collection: &str,
224 limit: usize,
225 ) -> crate::Result<Vec<(String, Vec<u8>)>> {
226 let docs = self.sparse.scan_documents(tid, collection, limit)?;
227
228 let config_key = (crate::types::TenantId::new(tid), collection.to_string());
229 let strict_schema = self.doc_configs.get(&config_key).and_then(|c| {
230 if let nodedb_physical::physical_plan::StorageMode::Strict { ref schema } =
231 c.storage_mode
232 {
233 Some(schema.clone())
234 } else {
235 None
236 }
237 });
238
239 if let Some(ref schema) = strict_schema {
240 // Strict: Binary Tuple → msgpack → inject "id".
241 let mut normalized = Vec::with_capacity(docs.len());
242 for (id, raw) in docs {
243 let mp = super::strict_format::binary_tuple_to_msgpack(&raw, schema)
244 .unwrap_or_else(|| super::doc_format::json_to_msgpack(&raw));
245 let mp = msgpack_scan::inject_str_field(&mp, "id", &id);
246 normalized.push((id, mp));
247 }
248 Ok(normalized)
249 } else {
250 // Schemaless: ensure standard msgpack, inject `id` field.
251 let mut normalized = Vec::with_capacity(docs.len());
252 for (id, raw) in docs {
253 let mp = super::doc_format::json_to_msgpack(&raw);
254 let mp = msgpack_scan::inject_str_field(&mp, "id", &id);
255 normalized.push((id, mp));
256 }
257 Ok(normalized)
258 }
259 }
260}
261
262/// Convert a single row from a `DecodedColumn` to a `nodedb_types::value::Value`.

Callers 1

scan_collectionMethod · 0.80

Calls 9

binary_tuple_to_msgpackFunction · 0.85
inject_str_fieldFunction · 0.85
scan_documentsMethod · 0.80
to_stringMethod · 0.80
json_to_msgpackFunction · 0.70
getMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected