Imports the view, source, or table with `id` into the provided dataflow description. [`OptimizerFeatures`] is used while running the [`Monotonic`] analysis. Panics if `id` refers to a non-importable item, such as an index or sink.
(
&mut self,
id: &GlobalId,
dataflow: &mut DataflowDesc,
features: &OptimizerFeatures,
)
| 306 | /// |
| 307 | /// Panics if `id` refers to a non-importable item, such as an index or sink. |
| 308 | pub fn import_into_dataflow( |
| 309 | &mut self, |
| 310 | id: &GlobalId, |
| 311 | dataflow: &mut DataflowDesc, |
| 312 | features: &OptimizerFeatures, |
| 313 | ) -> Result<(), OptimizerError> { |
| 314 | maybe_grow(|| { |
| 315 | // Avoid importing the item redundantly. |
| 316 | if dataflow.is_imported(id) { |
| 317 | return Ok(()); |
| 318 | } |
| 319 | |
| 320 | let monotonic = self.monotonic_object(*id, features); |
| 321 | |
| 322 | // A valid index is any index on `id` that is known to index oracle. |
| 323 | // Here, we import all indexes that belong to all imported collections. Later, |
| 324 | // `prune_and_annotate_dataflow_index_imports` runs at the end of the MIR |
| 325 | // pipeline, and removes unneeded index imports based on the optimized plan. |
| 326 | let mut valid_indexes = self.indexes_on(*id).peekable(); |
| 327 | if valid_indexes.peek().is_some() { |
| 328 | for (index_id, idx) in valid_indexes { |
| 329 | let index_desc = IndexDesc { |
| 330 | on_id: *id, |
| 331 | key: idx.keys.to_vec(), |
| 332 | }; |
| 333 | let entry = self.catalog.get_entry(id); |
| 334 | let desc = entry |
| 335 | .relation_desc() |
| 336 | .expect("indexes can only be built on items with descs"); |
| 337 | dataflow.import_index( |
| 338 | index_id, |
| 339 | index_desc, |
| 340 | ReprRelationType::from(desc.typ()), |
| 341 | monotonic, |
| 342 | ); |
| 343 | } |
| 344 | } else { |
| 345 | drop(valid_indexes); |
| 346 | let entry = self.catalog.get_entry(id); |
| 347 | // Note that the following match should be kept in sync with `sufficient_collections`. |
| 348 | match entry.item() { |
| 349 | CatalogItem::Table(table) => { |
| 350 | dataflow.import_source(*id, table.desc_for(id).into_typ(), monotonic); |
| 351 | } |
| 352 | CatalogItem::Source(source) => { |
| 353 | dataflow.import_source(*id, source.desc.typ().clone(), monotonic); |
| 354 | } |
| 355 | CatalogItem::View(view) => { |
| 356 | let expr = view.locally_optimized_expr.as_ref(); |
| 357 | self.import_view_into_dataflow(id, expr, dataflow, features)?; |
| 358 | } |
| 359 | CatalogItem::MaterializedView(mview) if mview.replacement_target.is_some() => { |
| 360 | // Can't read from replacements, use the view definition directly. |
| 361 | let expr = mview.locally_optimized_expr.as_ref(); |
| 362 | self.import_view_into_dataflow(id, expr, dataflow, features)?; |
| 363 | } |
| 364 | CatalogItem::MaterializedView(mview) => { |
| 365 | dataflow.import_source(*id, mview.desc_for(id).into_typ(), monotonic); |
no test coverage detected