diff --git a/Cargo.lock b/Cargo.lock index 510dfeb7..30a82014 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4028,7 +4028,7 @@ dependencies = [ "serde_json", "signal-hook", "soa_derive", - "sqlparser 0.51.0", + "sqlparser 0.50.0", "sqlx", "strum 0.26.3", "supabase-wrappers", @@ -5405,12 +5405,11 @@ dependencies = [ [[package]] name = "sqlparser" -version = "0.51.0" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fe11944a61da0da3f592e19a45ebe5ab92dc14a779907ff1f08fbb797bfefc7" +checksum = "b2e5b515a2bd5168426033e9efbfd05500114833916f1d5c268f938b4ee130ac" dependencies = [ "log", - "sqlparser_derive", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3029d340..e4923f68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ pgrx = "0.12.6" serde = "1.0.210" serde_json = "1.0.128" signal-hook = "0.3.17" -sqlparser = { version = "0.51.0", features = ["visitor"] } +sqlparser = "0.50.0" strum = { version = "0.26.3", features = ["derive"] } supabase-wrappers = { git = "https://github.com/paradedb/wrappers.git", default-features = false, rev = "f5ecb8d" } thiserror = "1.0.63" diff --git a/src/hooks/utility/view.rs b/src/hooks/utility/view.rs index 721296ec..c466a1c7 100644 --- a/src/hooks/utility/view.rs +++ b/src/hooks/utility/view.rs @@ -26,7 +26,10 @@ use crate::{duckdb::connection::execute, hooks::query::is_duckdb_query}; use super::set_search_path_by_pg; pub fn view_query(query_string: &core::ffi::CStr, stmt: *mut pg_sys::ViewStmt) -> Result { - if analyze_query(stmt)? { + let query = unsafe { (*stmt).query as *mut pg_sys::SelectStmt }; + let from_clause = unsafe { (*query).fromClause }; + + if analyze_from_clause(from_clause)? { // Push down the view creation query to DuckDB set_search_path_by_pg()?; execute(query_string.to_str()?, [])?; @@ -34,13 +37,7 @@ pub fn view_query(query_string: &core::ffi::CStr, stmt: *mut pg_sys::ViewStmt) - Ok(true) } -fn analyze_query(stmt: *mut pg_sys::ViewStmt) -> Result { - let query = unsafe { (*stmt).query as *mut pg_sys::SelectStmt }; - let from_clause = unsafe { (*query).fromClause }; - - analyze_from_clause(from_clause) -} - +/// Analyze the from clause to find the RangeVar node to check if it's a DuckDB query fn analyze_from_clause(from_clause: *mut pg_sys::List) -> Result { unsafe { let elements = (*from_clause).elements; @@ -61,6 +58,7 @@ fn analyze_from_clause(from_clause: *mut pg_sys::List) -> Result { Ok(false) } +/// Check if the RangeVar is a DuckDB query fn analyze_range_var(rv: *mut pg_sys::RangeVar) -> Result { let pg_relation = unsafe { let schema_id = RangeVarGetCreationNamespace(rv); @@ -78,6 +76,7 @@ fn analyze_range_var(rv: *mut pg_sys::RangeVar) -> Result { Ok(is_duckdb_query(&[pg_relation])) } +/// Check if the JoinExpr is a DuckDB query fn analyze_join_expr(join_expr: *mut pg_sys::JoinExpr) -> Result { pgrx::warning!("Analyzing JoinExpr"); @@ -89,6 +88,7 @@ fn analyze_join_expr(join_expr: *mut pg_sys::JoinExpr) -> Result { } } +/// Analyze the tree recursively to find the RangeVar node to check if it's a DuckDB query fn analyze_tree(mut tree: *mut pg_sys::Node) -> Result { while !tree.is_null() { unsafe {