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])
| 126 | /// 1. CdcEvent's own fields (event_type, collection, partition, etc.) |
| 127 | /// 2. new_value JSON object fields |
| 128 | fn 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 | /// |