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

Method to_json

nodedb/src/engine/graph/algo/result.rs:168–195  ·  view source on GitHub ↗

Serialize the result batch as JSON (for pgwire/REST response). Returns a JSON array of objects: `[{"node_id": "alice", "rank": 0.42}, ...]`. Used by tests; production code uses `to_msgpack()` + `decode_payload_to_json()`.

(&self)

Source from the content-addressed store, hash-verified

166 /// Returns a JSON array of objects: `[{"node_id": "alice", "rank": 0.42}, ...]`.
167 /// Used by tests; production code uses `to_msgpack()` + `decode_payload_to_json()`.
168 pub fn to_json(&self) -> Result<Vec<u8>, crate::Error> {
169 let schema = self.algorithm.result_schema();
170 let mut rows = Vec::with_capacity(self.row_count);
171
172 for row_idx in 0..self.row_count {
173 let mut obj = serde_json::Map::new();
174 for (col_idx, &(col_name, _col_type)) in schema.iter().enumerate() {
175 let (col_type, vec_idx) = self.column_map[col_idx];
176 let val = match col_type {
177 AlgoColumnType::Text => {
178 serde_json::Value::String(self.text_columns[vec_idx][row_idx].clone())
179 }
180 AlgoColumnType::Float64 => {
181 serde_json::json!(self.f64_columns[vec_idx][row_idx])
182 }
183 AlgoColumnType::Int64 => {
184 serde_json::json!(self.i64_columns[vec_idx][row_idx])
185 }
186 };
187 obj.insert(col_name.to_string(), val);
188 }
189 rows.push(serde_json::Value::Object(obj));
190 }
191
192 sonic_rs::to_vec(&rows).map_err(|e| crate::Error::Internal {
193 detail: format!("json serialization: {e}"),
194 })
195 }
196}
197
198impl zerompk::ToMessagePack for AlgoResultBatch {

Callers 15

diameter_pathFunction · 0.45
diameter_triangleFunction · 0.45
diameter_approximateFunction · 0.45
diameter_single_nodeFunction · 0.45
label_prop_triangleFunction · 0.45
label_prop_deterministicFunction · 0.45
closeness_pathFunction · 0.45
closeness_complete_graphFunction · 0.45
closeness_disconnectedFunction · 0.45
harmonic_pathFunction · 0.45
harmonic_disconnectedFunction · 0.45

Calls 6

result_schemaMethod · 0.80
to_stringMethod · 0.80
iterMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
pushMethod · 0.45

Tested by 15

diameter_pathFunction · 0.36
diameter_triangleFunction · 0.36
diameter_approximateFunction · 0.36
diameter_single_nodeFunction · 0.36
label_prop_triangleFunction · 0.36
label_prop_deterministicFunction · 0.36
closeness_pathFunction · 0.36
closeness_complete_graphFunction · 0.36
closeness_disconnectedFunction · 0.36
harmonic_pathFunction · 0.36
harmonic_disconnectedFunction · 0.36