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

Method execute_insert_select

nodedb/src/data/executor/handlers/insert_select.rs:18–127  ·  view source on GitHub ↗

INSERT ... SELECT: scan source collection, insert each document into target. Returns `{"inserted": N}` payload.

(
        &mut self,
        task: &ExecutionTask,
        tid: u64,
        target_collection: &str,
        source_collection: &str,
        source_filter_bytes: &[u8],
        source_limit: usize,

Source from the content-addressed store, hash-verified

16 ///
17 /// Returns `{"inserted": N}` payload.
18 pub(in crate::data::executor) fn execute_insert_select(
19 &mut self,
20 task: &ExecutionTask,
21 tid: u64,
22 target_collection: &str,
23 source_collection: &str,
24 source_filter_bytes: &[u8],
25 source_limit: usize,
26 ) -> Response {
27 debug!(core = self.core_id, %source_collection, %target_collection, "insert select");
28
29 let filters: Vec<ScanFilter> = if source_filter_bytes.is_empty() {
30 Vec::new()
31 } else {
32 match zerompk::from_msgpack(source_filter_bytes) {
33 Ok(f) => f,
34 Err(e) => {
35 return self.response_error(
36 task,
37 ErrorCode::Internal {
38 detail: format!("deserialize source filters: {e}"),
39 },
40 );
41 }
42 }
43 };
44
45 let fetch_limit = source_limit.saturating_mul(10).max(1000);
46 let mut source_docs = match self.scan_collection(tid, source_collection, fetch_limit) {
47 Ok(docs) => docs,
48 Err(e) => {
49 return self.response_error(
50 task,
51 ErrorCode::Internal {
52 detail: format!("scan source: {e}"),
53 },
54 );
55 }
56 };
57
58 if !filters.is_empty() {
59 source_docs.retain(|(_, data)| filters.iter().all(|f| f.matches_binary(data)));
60 }
61 source_docs.truncate(source_limit);
62
63 let txn = match self.sparse.begin_write() {
64 Ok(t) => t,
65 Err(e) => {
66 return self.response_error(
67 task,
68 ErrorCode::Internal {
69 detail: format!("begin write: {e}"),
70 },
71 );
72 }
73 };
74
75 let mut inserted = 0usize;

Callers 1

dispatch_documentMethod · 0.80

Calls 15

doc_id_to_surrogateFunction · 0.85
encode_jsonFunction · 0.85
response_errorMethod · 0.80
scan_collectionMethod · 0.80
matches_binaryMethod · 0.80
begin_writeMethod · 0.80
apply_point_putMethod · 0.80
to_stringMethod · 0.80
mark_dirtyMethod · 0.80
response_with_payloadMethod · 0.80
is_emptyMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected