Skip to content

Commit 9e83b85

Browse files
committed
refactor: avoid hardcoded catalog name in library
1 parent 9896a73 commit 9e83b85

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

datafusion-postgres-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async fn setup_session_context(
171171
}
172172

173173
// Register pg_catalog
174-
setup_pg_catalog(session_context)?;
174+
setup_pg_catalog(session_context, "datafusion")?;
175175

176176
Ok(())
177177
}

datafusion-postgres/src/pg_catalog.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use datafusion::catalog::streaming::StreamingTable;
1010
use datafusion::catalog::{CatalogProviderList, MemTable, SchemaProvider};
1111
use datafusion::common::utils::SingleRowListArrayBuilder;
1212
use datafusion::datasource::TableProvider;
13-
use datafusion::error::Result;
13+
use datafusion::error::{DataFusionError, Result};
1414
use datafusion::execution::{SendableRecordBatchStream, TaskContext};
1515
use datafusion::logical_expr::{ColumnarValue, ScalarUDF, Volatility};
1616
use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
@@ -653,11 +653,16 @@ pub fn create_current_schema_udf() -> ScalarUDF {
653653
}
654654

655655
/// Install pg_catalog and postgres UDFs to current `SessionContext`
656-
pub fn setup_pg_catalog(session_context: &SessionContext) -> Result<()> {
656+
pub fn setup_pg_catalog(session_context: &SessionContext, catalog_name: &str) -> Result<()> {
657657
let pg_catalog = PgCatalogSchemaProvider::new(session_context.state().catalog_list().clone());
658658
session_context
659-
.catalog("datafusion")
660-
.unwrap()
659+
.catalog(catalog_name)
660+
.ok_or_else(|| {
661+
DataFusionError::Configuration(format!(
662+
"Catalog not found when registering pg_catalog: {}",
663+
catalog_name
664+
))
665+
})?
661666
.register_schema("pg_catalog", Arc::new(pg_catalog))?;
662667

663668
session_context.register_udf(create_current_schema_udf());

0 commit comments

Comments
 (0)