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

Function extract_bytes

nodedb-query/src/msgpack_scan/aggregate_helpers.rs:65–72  ·  view source on GitHub ↗

Extract a field or expression result as raw msgpack bytes. Used by `count_distinct`, `approx_count_distinct`, `approx_topk`, etc.

(doc: &[u8], field: &str, expr: Option<&SqlExpr>)

Source from the content-addressed store, hash-verified

63/// Extract a field or expression result as raw msgpack bytes.
64/// Used by `count_distinct`, `approx_count_distinct`, `approx_topk`, etc.
65pub fn extract_bytes(doc: &[u8], field: &str, expr: Option<&SqlExpr>) -> Option<Vec<u8>> {
66 if let Some(expr) = expr {
67 let val = eval_expr(doc, expr)?;
68 return nodedb_types::json_msgpack::value_to_msgpack(&val).ok();
69 }
70 let (start, end) = extract_field(doc, 0, field)?;
71 Some(doc[start..end].to_vec())
72}
73
74/// Returns `Some(())` when the field is present and non-null.
75/// Used by `count(field)` accumulator to count non-null values.

Callers 1

feedMethod · 0.85

Calls 5

value_to_msgpackFunction · 0.85
extract_fieldFunction · 0.85
eval_exprFunction · 0.70
okMethod · 0.45
to_vecMethod · 0.45

Tested by

no test coverage detected