Applies adjustments to second part of a pipeline when it's split: - append Select to preceding pipeline - prepend From to atomic pipeline - redefine columns materialized in atomic pipeline - redirect all references to original columns to the new ones
(
ctx: &mut AnchorContext,
preceding: Vec<SqlTransform>,
atomic: Vec<SqlTransform>,
)
| 226 | /// - redefine columns materialized in atomic pipeline |
| 227 | /// - redirect all references to original columns to the new ones |
| 228 | pub(super) fn anchor_split( |
| 229 | ctx: &mut AnchorContext, |
| 230 | preceding: Vec<SqlTransform>, |
| 231 | atomic: Vec<SqlTransform>, |
| 232 | ) -> Vec<SqlTransform> { |
| 233 | let new_tid = ctx.tid.gen(); |
| 234 | |
| 235 | let preceding_select = &preceding.last().unwrap().as_super().unwrap(); |
| 236 | let cols_at_split = preceding_select.as_select().unwrap(); |
| 237 | |
| 238 | log::debug!("split pipeline, first pipeline output: {cols_at_split:?}"); |
| 239 | |
| 240 | // redefine columns of the atomic pipeline |
| 241 | let mut cid_redirects = HashMap::<CId, CId>::new(); |
| 242 | let mut new_columns = Vec::new(); |
| 243 | let mut used_new_names = HashSet::new(); |
| 244 | for old_cid in cols_at_split { |
| 245 | let new_cid = ctx.cid.gen(); |
| 246 | |
| 247 | let old_name = ctx.ensure_column_name(*old_cid).cloned(); |
| 248 | |
| 249 | let mut new_name = old_name; |
| 250 | if let Some(new) = &mut new_name { |
| 251 | if used_new_names.contains(new) { |
| 252 | *new = ctx.col_name.gen(); |
| 253 | ctx.column_names.insert(*old_cid, new.clone()); |
| 254 | } |
| 255 | |
| 256 | used_new_names.insert(new.clone()); |
| 257 | ctx.column_names.insert(new_cid, new.clone()); |
| 258 | } |
| 259 | |
| 260 | let old_def = ctx.column_decls.get(old_cid).unwrap(); |
| 261 | |
| 262 | let col = match old_def { |
| 263 | ColumnDecl::RelationColumn(_, _, RelationColumn::Wildcard) => RelationColumn::Wildcard, |
| 264 | _ => RelationColumn::Single(new_name), |
| 265 | }; |
| 266 | |
| 267 | new_columns.push((col, new_cid)); |
| 268 | cid_redirects.insert(*old_cid, new_cid); |
| 269 | } |
| 270 | |
| 271 | // define a new table |
| 272 | let columns = cols_at_split |
| 273 | .iter() |
| 274 | .map(|_| RelationColumn::Single(None)) |
| 275 | .collect_vec(); |
| 276 | ctx.table_decls.insert( |
| 277 | new_tid, |
| 278 | SqlTableDecl { |
| 279 | id: new_tid, |
| 280 | name: None, |
| 281 | relation: RelationStatus::NotYetDefined(RelationAdapter::Preprocessed( |
| 282 | preceding, columns, |
| 283 | )), |
| 284 | redirect_to: None, |
| 285 | }, |
no test coverage detected