Purifies a CREATE MATERIALIZED VIEW statement. Additionally, it adjusts `resolved_ids` if references to ids appear or disappear during the purification. Note that in contrast with [`purify_statement`], this doesn't need to be async, because this function is not making any network calls.
(
catalog: impl SessionCatalog,
mz_now: Option<Timestamp>,
cmvs: &mut CreateMaterializedViewStatement<Aug>,
resolved_ids: &mut ResolvedIds,
)
| 2792 | /// Note that in contrast with [`purify_statement`], this doesn't need to be async, because |
| 2793 | /// this function is not making any network calls. |
| 2794 | pub fn purify_create_materialized_view_options( |
| 2795 | catalog: impl SessionCatalog, |
| 2796 | mz_now: Option<Timestamp>, |
| 2797 | cmvs: &mut CreateMaterializedViewStatement<Aug>, |
| 2798 | resolved_ids: &mut ResolvedIds, |
| 2799 | ) { |
| 2800 | // 0. Preparations: |
| 2801 | // Prepare an expression that calls `mz_now()`, which we can insert in various later steps. |
| 2802 | let (mz_now_id, mz_now_expr) = { |
| 2803 | let item = catalog |
| 2804 | .resolve_function(&PartialItemName { |
| 2805 | database: None, |
| 2806 | schema: Some(MZ_NOW_SCHEMA.to_string()), |
| 2807 | item: MZ_NOW_NAME.to_string(), |
| 2808 | }) |
| 2809 | .expect("we should be able to resolve mz_now"); |
| 2810 | ( |
| 2811 | item.id(), |
| 2812 | Expr::Function(Function { |
| 2813 | name: ResolvedItemName::Item { |
| 2814 | id: item.id(), |
| 2815 | qualifiers: item.name().qualifiers.clone(), |
| 2816 | full_name: catalog.resolve_full_name(item.name()), |
| 2817 | print_id: false, |
| 2818 | version: RelationVersionSelector::Latest, |
| 2819 | }, |
| 2820 | args: FunctionArgs::Args { |
| 2821 | args: Vec::new(), |
| 2822 | order_by: Vec::new(), |
| 2823 | }, |
| 2824 | filter: None, |
| 2825 | over: None, |
| 2826 | distinct: false, |
| 2827 | }), |
| 2828 | ) |
| 2829 | }; |
| 2830 | // Prepare the `mz_timestamp` type. |
| 2831 | let (mz_timestamp_id, mz_timestamp_type) = { |
| 2832 | let item = catalog.get_system_type("mz_timestamp"); |
| 2833 | let full_name = catalog.resolve_full_name(item.name()); |
| 2834 | ( |
| 2835 | item.id(), |
| 2836 | ResolvedDataType::Named { |
| 2837 | id: item.id(), |
| 2838 | qualifiers: item.name().qualifiers.clone(), |
| 2839 | full_name, |
| 2840 | modifiers: vec![], |
| 2841 | print_id: true, |
| 2842 | }, |
| 2843 | ) |
| 2844 | }; |
| 2845 | |
| 2846 | let mut introduced_mz_timestamp = false; |
| 2847 | |
| 2848 | for option in cmvs.with_options.iter_mut() { |
| 2849 | // 1. Purify `REFRESH AT CREATION` to `REFRESH AT mz_now()`. |
| 2850 | if matches!( |
| 2851 | option.value, |
no test coverage detected