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

Function extract_group_key

nodedb/src/event/streaming_mv/processor.rs:128–153  ·  view source on GitHub ↗

Extract the GROUP BY key by concatenating column values from the event. Looks for column values in: 1. CdcEvent's own fields (event_type, collection, partition, etc.) 2. new_value JSON object fields

(event: &CdcEvent, group_by_columns: &[String])

Source from the content-addressed store, hash-verified

126/// 1. CdcEvent's own fields (event_type, collection, partition, etc.)
127/// 2. new_value JSON object fields
128fn extract_group_key(event: &CdcEvent, group_by_columns: &[String]) -> String {
129 let mut parts = Vec::with_capacity(group_by_columns.len());
130
131 for col in group_by_columns {
132 let val = match col.as_str() {
133 "event_type" | "op" => event.op.clone(),
134 "collection" => event.collection.clone(),
135 "partition" => event.partition.to_string(),
136 "row_id" => event.row_id.clone(),
137 "tenant_id" => event.tenant_id.to_string(),
138 // Look in new_value JSON.
139 field => event
140 .new_value
141 .as_ref()
142 .and_then(|v| v.get(field))
143 .map(|v| match v {
144 serde_json::Value::String(s) => s.clone(),
145 other => other.to_string(),
146 })
147 .unwrap_or_else(|| "NULL".to_string()),
148 };
149 parts.push(val);
150 }
151
152 parts.join(":")
153}
154
155/// Extract a numeric value for an aggregate function from the event.
156///

Callers 4

update_mvFunction · 0.85

Calls 8

to_stringMethod · 0.80
joinMethod · 0.80
lenMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45
as_refMethod · 0.45
getMethod · 0.45
pushMethod · 0.45