Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prod Promotion -- v0.3.2 #206

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 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
@@ -1,7 +1,7 @@
[package]
name = "pg_analytics"
description = "Postgres for analytics, powered by DuckDB"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
license = "PostgreSQL"

Expand Down
1 change: 1 addition & 0 deletions sql/pg_analytics--0.3.1--0.3.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\echo Use "ALTER EXTENSION pg_analytics UPDATE TO '0.3.2'" to load this file. \quit
38 changes: 23 additions & 15 deletions src/duckdb/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use signal_hook::consts::signal::*;
use signal_hook::iterator::Signals;
use std::cell::UnsafeCell;
use std::collections::HashMap;
use std::ffi::CStr;
use std::sync::Once;
use std::thread;

Expand All @@ -35,6 +36,18 @@ static INIT: Once = Once::new();

fn init_globals() {
let conn = Connection::open_in_memory().expect("failed to open duckdb connection");

// Force DuckDB to install its extensions in the PGDATA directory, which is writable,
// in case the rest of the filesystem is read-only
let _ =
set_duckdb_extension_directory(&conn).expect("failed to set duckdb extension directory");

// duckdb-rs stopped bundling in httpfs, so we need to load it ourselves
conn.execute("INSTALL httpfs", [])
.expect("failed to install httpfs");
conn.execute("LOAD httpfs", [])
.expect("failed to load httpfs");

unsafe {
GLOBAL_CONNECTION = Some(UnsafeCell::new(conn));
GLOBAL_STATEMENT = Some(UnsafeCell::new(None));
Expand Down Expand Up @@ -255,14 +268,17 @@ pub fn set_search_path(search_path: Vec<String>) -> Result<()> {
Ok(())
}

pub fn set_duckdb_extension_directory(extension_directory_path: &str) -> Result<()> {
// Set duckdb extension directory
execute(
format!("SET extension_directory = '{extension_directory_path}'").as_str(),
pub fn set_duckdb_extension_directory(conn: &Connection) -> Result<usize> {
let data_dir = unsafe {
CStr::from_ptr(pgrx::pg_sys::DataDir)
.to_str()
.map_err(|e| anyhow::anyhow!("Failed to convert DataDir to &str: {}", e))?
};
conn.execute(
format!("SET extension_directory = '{data_dir}'").as_str(),
[],
)?;

Ok(())
)
.map_err(|err| anyhow!("{err}"))
}

pub fn execute_explain(query: &str) -> Result<String> {
Expand All @@ -282,11 +298,3 @@ pub fn execute_explain(query: &str) -> Result<String> {

Ok(rows.join(""))
}

pub fn install_httpfs() -> Result<()> {
if !check_extension_loaded("httpfs")? {
execute("INSTALL httpfs", [])?;
execute("LOAD httpfs", [])?;
}
Ok(())
}
14 changes: 0 additions & 14 deletions src/fdw/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ use anyhow::{anyhow, bail, Result};
use duckdb::arrow::array::RecordBatch;
use pgrx::*;
use std::collections::HashMap;
use std::ffi::CStr;
use strum::IntoEnumIterator;
use supabase_wrappers::prelude::*;
use thiserror::Error;

use super::handler::FdwHandler;
use crate::duckdb::connection;
use crate::fdw::base::connection::set_duckdb_extension_directory;
use crate::schema::cell::*;

#[cfg(debug_assertions)]
Expand Down Expand Up @@ -226,18 +224,6 @@ pub fn register_duckdb_view(
connection::create_secret(DEFAULT_SECRET, user_mapping_options)?;
}

// In CloudNativePG, the filesystem is read-only. To work around this, we force
// DuckDB to install its extensions in the PGDATA directory, which is writable.
let data_dir = unsafe {
CStr::from_ptr(pgrx::pg_sys::DataDir)
.to_str()
.map_err(|e| anyhow::anyhow!("Failed to convert DataDir to &str: {}", e))?
};
let _ = set_duckdb_extension_directory(data_dir);

// duckdb-rs stopped bundling in httpfs, so we need to load it ourselves
connection::install_httpfs()?;

if !connection::view_exists(table_name, schema_name)? {
// Initialize DuckDB view
connection::execute(
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tests"
description = "Test suite for pg_analytics"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
license = "PostgreSQL"

Expand Down