query/query_engine/
options.rs1use session::context::QueryContextRef;
16use snafu::ensure;
17
18use crate::error::{QueryAccessDeniedSnafu, Result};
19
20#[derive(Default, Clone)]
21pub struct QueryOptions {
22 pub disallow_cross_catalog_query: bool,
23}
24
25pub fn validate_catalog_and_schema(
27 catalog: &str,
28 schema: &str,
29 query_ctx: &QueryContextRef,
30) -> Result<()> {
31 ensure!(
32 catalog == query_ctx.current_catalog(),
33 QueryAccessDeniedSnafu {
34 catalog: catalog.to_string(),
35 schema: schema.to_string(),
36 }
37 );
38
39 Ok(())
40}
41
42#[cfg(test)]
43mod tests {
44
45 use std::sync::Arc;
46
47 use session::context::QueryContext;
48
49 use super::*;
50
51 #[test]
52 fn test_validate_catalog_and_schema() {
53 let context = Arc::new(QueryContext::with("greptime", "public"));
54
55 validate_catalog_and_schema("greptime", "public", &context).unwrap();
56 let re = validate_catalog_and_schema("greptime", "private_schema", &context);
57 assert!(re.is_ok());
58 let re = validate_catalog_and_schema("wrong_catalog", "public", &context);
59 assert!(re.is_err());
60 let re = validate_catalog_and_schema("wrong_catalog", "wrong_schema", &context);
61 assert!(re.is_err());
62
63 validate_catalog_and_schema("greptime", "information_schema", &context).unwrap();
64 }
65}