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: mark GUC prefix reserved #599

Merged
merged 1 commit into from
Sep 24, 2024
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
18 changes: 15 additions & 3 deletions src/gucs/embedding.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use super::guc_string_parse;
use embedding::OpenAIOptions;
use pgrx::guc::{GucContext, GucFlags, GucRegistry, GucSetting};
use std::ffi::CStr;

pub fn openai_options() -> OpenAIOptions {
let base_url = guc_string_parse(&OPENAI_BASE_URL, "vectors.openai_base_url");
let api_key = guc_string_parse(&OPENAI_API_KEY, "vectors.openai_api_key");
use crate::error::*;
use pgrx::guc::GucSetting;
use std::ffi::CStr;
fn parse(target: &'static GucSetting<Option<&'static CStr>>, name: &'static str) -> String {
let value = match target.get() {
Some(s) => s,
None => bad_guc_literal(name, "should not be `NULL`"),
};
match value.to_str() {
Ok(s) => s.to_string(),
Err(_e) => bad_guc_literal(name, "should be a valid UTF-8 string"),
}
}
let base_url = parse(&OPENAI_BASE_URL, "vectors.openai_base_url");
let api_key = parse(&OPENAI_API_KEY, "vectors.openai_api_key");
OpenAIOptions { base_url, api_key }
}

Expand Down
22 changes: 4 additions & 18 deletions src/gucs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use crate::error::*;
use pgrx::guc::GucSetting;
use std::ffi::CStr;

pub mod embedding;
pub mod executing;
pub mod internal;
Expand All @@ -13,19 +9,9 @@ pub unsafe fn init() {
internal::init();
executing::init();
embedding::init();
}
}

fn guc_string_parse(
target: &'static GucSetting<Option<&'static CStr>>,
name: &'static str,
) -> String {
let value = match target.get() {
Some(s) => s,
None => bad_guc_literal(name, "should not be `NULL`"),
};
match value.to_str() {
Ok(s) => s.to_string(),
Err(_e) => bad_guc_literal(name, "should be a valid UTF-8 string"),
#[cfg(feature = "pg14")]
pgrx::pg_sys::EmitWarningsOnPlaceholders(c"vectors".as_ptr());
#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
pgrx::pg_sys::MarkGUCPrefixReserved(c"vectors".as_ptr());
}
}