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

Method execute_convert_collection

nodedb/src/data/executor/handlers/convert.rs:26–75  ·  view source on GitHub ↗

Execute a collection conversion. - `TO document` / `TO kv`: no re-encoding needed. Catalog update on Control Plane. - `TO strict`: re-encode each document as a Binary Tuple using the provided schema. Documents that fail validation are skipped and counted as errors.

(
        &mut self,
        task: &ExecutionTask,
        tid: u64,
        collection: &str,
        target_type: &str,
        schema_json: &str,
    )

Source from the content-addressed store, hash-verified

24 /// - `TO strict`: re-encode each document as a Binary Tuple using the provided
25 /// schema. Documents that fail validation are skipped and counted as errors.
26 pub(in crate::data::executor) fn execute_convert_collection(
27 &mut self,
28 task: &ExecutionTask,
29 tid: u64,
30 collection: &str,
31 target_type: &str,
32 schema_json: &str,
33 ) -> Response {
34 tracing::debug!(
35 core = self.core_id,
36 %collection,
37 target_type,
38 "converting collection"
39 );
40
41 match target_type {
42 "document_strict" => self.convert_to_strict(task, tid, collection, schema_json),
43 "document_schemaless" | "kv" => {
44 // No re-encoding needed — sparse engine stores raw MessagePack bytes
45 // regardless of collection type. Catalog type update handled by
46 // Control Plane after this returns.
47 let count = self
48 .sparse
49 .scan_documents(tid, collection, usize::MAX)
50 .map(|docs| docs.len() as u64)
51 .unwrap_or(0);
52
53 let result = serde_json::json!({
54 "converted": count,
55 "target_type": target_type,
56 "collection": collection,
57 });
58 match response_codec::encode_json(&result) {
59 Ok(payload) => self.response_with_payload(task, payload),
60 Err(e) => self.response_error(
61 task,
62 ErrorCode::Internal {
63 detail: e.to_string(),
64 },
65 ),
66 }
67 }
68 other => self.response_error(
69 task,
70 ErrorCode::Internal {
71 detail: format!("unsupported conversion target: {other}"),
72 },
73 ),
74 }
75 }
76
77 /// Convert to strict mode: re-encode each document as a Binary Tuple.
78 fn convert_to_strict(

Callers 1

dispatch_metaMethod · 0.80

Calls 7

encode_jsonFunction · 0.85
convert_to_strictMethod · 0.80
scan_documentsMethod · 0.80
response_with_payloadMethod · 0.80
response_errorMethod · 0.80
to_stringMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected