Skip to content

Commit b4b9fdf

Browse files
JeadieCopilot
andauthored
Add catalog name to foreign key metadata in postgres catalog (spiceai#10917)
* fix(pg catalog): include catalog in FK foreign_table metadata Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(pg): remove redundant catalog_name FK parameter Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Jeadie <jeadie@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 44360da commit b4b9fdf

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

crates/data_components/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use datafusion::{
3737
/// [
3838
/// {
3939
/// "columns": ["customer_id"],
40-
/// "foreign_table": "public.customers",
40+
/// "foreign_table": "catalog.public.customers",
4141
/// "foreign_columns": ["id"]
4242
/// }
4343
/// ]

crates/data_components/src/postgres/provider.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type ForeignKeyMap = HashMap<String, Vec<ForeignKeyConstraint>>;
7070
/// A catalog provider for `PostgreSQL` that discovers schemas and tables
7171
/// by querying `information_schema`.
7272
pub struct PostgresCatalogProvider {
73+
catalog_name: String,
7374
pool: Arc<PostgresConnectionPool>,
7475
table_creator: Arc<dyn Read>,
7576
schemas: RwLock<HashMap<String, Arc<PostgresSchemaProvider>>>,
@@ -86,11 +87,13 @@ impl std::fmt::Debug for PostgresCatalogProvider {
8687
impl PostgresCatalogProvider {
8788
#[must_use]
8889
pub fn new(
90+
catalog_name: String,
8991
pool: Arc<PostgresConnectionPool>,
9092
table_creator: Arc<dyn Read>,
9193
include: Option<GlobSet>,
9294
) -> Self {
9395
Self {
96+
catalog_name,
9497
pool,
9598
table_creator,
9699
schemas: RwLock::new(HashMap::new()),
@@ -189,7 +192,10 @@ impl PostgresCatalogProvider {
189192

190193
let table_constraints = constraints_by_table.entry(table_name).or_default();
191194

192-
let foreign_table = format!("{referenced_schema}.{referenced_table}");
195+
let foreign_table = format!(
196+
"{}.{}.{}",
197+
self.catalog_name, referenced_schema, referenced_table
198+
);
193199
let fk =
194200
table_constraints
195201
.entry(constraint_name)

crates/runtime/src/catalogconnector/postgres.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl CatalogConnector for PostgresCatalog {
8888
let table_factory = Arc::new(PostgresTableFactory::new(Arc::clone(&pool)));
8989

9090
let catalog_provider = Arc::new(PostgresCatalogProvider::new(
91+
catalog.name.clone(),
9192
pool,
9293
table_factory,
9394
catalog.include.clone(),

0 commit comments

Comments
 (0)