Resolves `object` to a table expr, i.e. creating a `Get` or inlining a CTE.
(
&self,
object: ResolvedItemName,
)
| 6625 | /// Resolves `object` to a table expr, i.e. creating a `Get` or inlining a |
| 6626 | /// CTE. |
| 6627 | pub fn resolve_table_name( |
| 6628 | &self, |
| 6629 | object: ResolvedItemName, |
| 6630 | ) -> Result<(HirRelationExpr, Scope), PlanError> { |
| 6631 | match object { |
| 6632 | ResolvedItemName::Item { |
| 6633 | id, |
| 6634 | full_name, |
| 6635 | version, |
| 6636 | .. |
| 6637 | } => { |
| 6638 | let item = self.scx.get_item(&id).at_version(version); |
| 6639 | let desc = match item.relation_desc() { |
| 6640 | Some(desc) => desc.clone(), |
| 6641 | None => { |
| 6642 | return Err(PlanError::InvalidDependency { |
| 6643 | name: full_name.to_string(), |
| 6644 | item_type: item.item_type().to_string(), |
| 6645 | }); |
| 6646 | } |
| 6647 | }; |
| 6648 | let expr = HirRelationExpr::Get { |
| 6649 | id: Id::Global(item.global_id()), |
| 6650 | typ: desc.typ().clone(), |
| 6651 | }; |
| 6652 | |
| 6653 | let name = full_name.into(); |
| 6654 | let scope = Scope::from_source(Some(name), desc.iter_names().cloned()); |
| 6655 | |
| 6656 | Ok((expr, scope)) |
| 6657 | } |
| 6658 | ResolvedItemName::Cte { id, name } => { |
| 6659 | let name = name.into(); |
| 6660 | let cte = self.ctes.get(&id).unwrap(); |
| 6661 | let expr = HirRelationExpr::Get { |
| 6662 | id: Id::Local(id), |
| 6663 | typ: cte.desc.typ().clone(), |
| 6664 | }; |
| 6665 | |
| 6666 | let scope = Scope::from_source(Some(name), cte.desc.iter_names()); |
| 6667 | |
| 6668 | Ok((expr, scope)) |
| 6669 | } |
| 6670 | ResolvedItemName::Error => bail_internal!("should have been caught in name resolution"), |
| 6671 | } |
| 6672 | } |
| 6673 | |
| 6674 | /// The returned String is more detailed when the `postgres_compat` flag is not set. However, |
| 6675 | /// the flag should be set in, e.g., the implementation of the `pg_typeof` function. |
no test coverage detected