Skip to main content

micromegas/servers/
view_ddl.rs

1//! Admin gate for `CREATE`/`DROP MATERIALIZED VIEW`. The statement parser itself lives in
2//! `micromegas_analytics::lakehouse::view_ddl` (so the `check_view_merge` UDTF can reuse it);
3//! `ViewDdl` and `parse_view_ddl` are re-exported here for the Flight SQL front end.
4
5use micromegas_analytics::lakehouse::read_scope::CallerContext;
6pub use micromegas_analytics::lakehouse::view_ddl::{ViewDdl, parse_view_ddl};
7use tonic::Status;
8
9/// The same admin gate as the ten admin-gated lakehouse UDTFs/UDFs
10/// (`query.rs::register_lakehouse_functions`'s `if lakehouse_admin` block), pulled out as a
11/// standalone function since this path never builds a caller session context to register a UDTF
12/// against in the first place. Also load-bearing beyond the usual reason: a DDL view's queries
13/// are planned and materialized under `CallerContext::maintenance()` (`ReadScope::All`), so an
14/// author sees every audience regardless of their own read scope.
15pub fn authorize_view_ddl(caller: &CallerContext) -> Result<(), Status> {
16    if !caller.is_admin {
17        return Err(Status::permission_denied(
18            "CREATE/DROP MATERIALIZED VIEW requires admin privileges",
19        ));
20    }
21    Ok(())
22}