Skip to content

Commit

Permalink
chore: Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Weijun-H committed Oct 16, 2024
1 parent eeecfd1 commit eaa0a90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions src/hooks/utility/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@ 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<bool> {
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()?, [])?;
}
Ok(true)
}

fn analyze_query(stmt: *mut pg_sys::ViewStmt) -> Result<bool> {
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<bool> {
unsafe {
let elements = (*from_clause).elements;
Expand All @@ -61,6 +58,7 @@ fn analyze_from_clause(from_clause: *mut pg_sys::List) -> Result<bool> {
Ok(false)
}

/// Check if the RangeVar is a DuckDB query
fn analyze_range_var(rv: *mut pg_sys::RangeVar) -> Result<bool> {
let pg_relation = unsafe {
let schema_id = RangeVarGetCreationNamespace(rv);
Expand All @@ -78,6 +76,7 @@ fn analyze_range_var(rv: *mut pg_sys::RangeVar) -> Result<bool> {
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<bool> {
pgrx::warning!("Analyzing JoinExpr");

Expand All @@ -89,6 +88,7 @@ fn analyze_join_expr(join_expr: *mut pg_sys::JoinExpr) -> Result<bool> {
}
}

/// 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<bool> {
while !tree.is_null() {
unsafe {
Expand Down

0 comments on commit eaa0a90

Please sign in to comment.