Skip to content

Commit f2b3671

Browse files
authored
refactor: update CatalogInfo signatures (#162)
1 parent a230f06 commit f2b3671

File tree

6 files changed

+31
-22
lines changed

6 files changed

+31
-22
lines changed

datafusion-postgres/src/pg_catalog/catalog_info.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ use datafusion::{
1010
/// Define the interface for retrieve catalog data for pg_catalog tables
1111
#[async_trait]
1212
pub trait CatalogInfo: Clone + Send + Sync + Debug + 'static {
13-
fn catalog_names(&self) -> Vec<String>;
13+
fn catalog_names(&self) -> Result<Vec<String>, DataFusionError>;
1414

15-
fn schema_names(&self, catalog_name: &str) -> Option<Vec<String>>;
15+
fn schema_names(&self, catalog_name: &str) -> Result<Option<Vec<String>>, DataFusionError>;
1616

17-
fn table_names(&self, catalog_name: &str, schema_name: &str) -> Option<Vec<String>>;
17+
fn table_names(
18+
&self,
19+
catalog_name: &str,
20+
schema_name: &str,
21+
) -> Result<Option<Vec<String>>, DataFusionError>;
1822

1923
async fn table_schema(
2024
&self,
@@ -33,18 +37,23 @@ pub trait CatalogInfo: Clone + Send + Sync + Debug + 'static {
3337

3438
#[async_trait]
3539
impl CatalogInfo for Arc<dyn CatalogProviderList> {
36-
fn catalog_names(&self) -> Vec<String> {
37-
CatalogProviderList::catalog_names(self.as_ref())
40+
fn catalog_names(&self) -> Result<Vec<String>, DataFusionError> {
41+
Ok(CatalogProviderList::catalog_names(self.as_ref()))
3842
}
3943

40-
fn schema_names(&self, catalog_name: &str) -> Option<Vec<String>> {
41-
self.catalog(catalog_name).map(|c| c.schema_names())
44+
fn schema_names(&self, catalog_name: &str) -> Result<Option<Vec<String>>, DataFusionError> {
45+
Ok(self.catalog(catalog_name).map(|c| c.schema_names()))
4246
}
4347

44-
fn table_names(&self, catalog_name: &str, schema_name: &str) -> Option<Vec<String>> {
45-
self.catalog(catalog_name)
48+
fn table_names(
49+
&self,
50+
catalog_name: &str,
51+
schema_name: &str,
52+
) -> Result<Option<Vec<String>>, DataFusionError> {
53+
Ok(self
54+
.catalog(catalog_name)
4655
.and_then(|c| c.schema(schema_name))
47-
.map(|s| s.table_names())
56+
.map(|s| s.table_names()))
4857
}
4958

5059
async fn table_schema(

datafusion-postgres/src/pg_catalog/pg_attribute.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ impl<C: CatalogInfo> PgAttributeTable<C> {
105105
// original one in case that schemas or tables were dropped.
106106
let mut swap_cache = HashMap::new();
107107

108-
for catalog_name in this.catalog_list.catalog_names() {
109-
if let Some(schema_names) = this.catalog_list.schema_names(&catalog_name) {
108+
for catalog_name in this.catalog_list.catalog_names()? {
109+
if let Some(schema_names) = this.catalog_list.schema_names(&catalog_name)? {
110110
for schema_name in schema_names {
111111
if let Some(table_names) =
112-
this.catalog_list.table_names(&catalog_name, &schema_name)
112+
this.catalog_list.table_names(&catalog_name, &schema_name)?
113113
{
114114
// Process all tables in this schema
115115
for table_name in table_names {

datafusion-postgres/src/pg_catalog/pg_class.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<C: CatalogInfo> PgClassTable<C> {
117117
let mut swap_cache = HashMap::new();
118118

119119
// Iterate through all catalogs and schemas
120-
for catalog_name in this.catalog_list.catalog_names() {
120+
for catalog_name in this.catalog_list.catalog_names()? {
121121
let cache_key = OidCacheKey::Catalog(catalog_name.clone());
122122
let catalog_oid = if let Some(oid) = oid_cache.get(&cache_key) {
123123
*oid
@@ -126,7 +126,7 @@ impl<C: CatalogInfo> PgClassTable<C> {
126126
};
127127
swap_cache.insert(cache_key, catalog_oid);
128128

129-
if let Some(schema_names) = this.catalog_list.schema_names(&catalog_name) {
129+
if let Some(schema_names) = this.catalog_list.schema_names(&catalog_name)? {
130130
for schema_name in schema_names {
131131
let cache_key = OidCacheKey::Schema(catalog_name.clone(), schema_name.clone());
132132
let schema_oid = if let Some(oid) = oid_cache.get(&cache_key) {
@@ -141,7 +141,7 @@ impl<C: CatalogInfo> PgClassTable<C> {
141141

142142
// Now process all tables in this schema
143143
if let Some(table_names) =
144-
this.catalog_list.table_names(&catalog_name, &schema_name)
144+
this.catalog_list.table_names(&catalog_name, &schema_name)?
145145
{
146146
for table_name in table_names {
147147
let cache_key = OidCacheKey::Table(

datafusion-postgres/src/pg_catalog/pg_database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<C: CatalogInfo> PgDatabaseTable<C> {
8080
let mut oid_cache = this.oid_cache.write().await;
8181

8282
// Add a record for each catalog (treating catalogs as "databases")
83-
for catalog_name in this.catalog_list.catalog_names() {
83+
for catalog_name in this.catalog_list.catalog_names()? {
8484
let cache_key = OidCacheKey::Catalog(catalog_name.clone());
8585
let catalog_oid = if let Some(oid) = oid_cache.get(&cache_key) {
8686
*oid

datafusion-postgres/src/pg_catalog/pg_namespace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ impl<C: CatalogInfo> PgNamespaceTable<C> {
6262
let mut oid_cache = this.oid_cache.write().await;
6363

6464
// Now add all schemas from DataFusion catalogs
65-
for catalog_name in this.catalog_list.catalog_names() {
66-
if let Some(schema_names) = this.catalog_list.schema_names(&catalog_name) {
65+
for catalog_name in this.catalog_list.catalog_names()? {
66+
if let Some(schema_names) = this.catalog_list.schema_names(&catalog_name)? {
6767
for schema_name in schema_names {
6868
let cache_key = OidCacheKey::Schema(catalog_name.clone(), schema_name.clone());
6969
let schema_oid = if let Some(oid) = oid_cache.get(&cache_key) {

datafusion-postgres/src/pg_catalog/pg_tables.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ impl<C: CatalogInfo> PgTablesTable<C> {
4949
let mut row_security = Vec::new();
5050

5151
// Iterate through all catalogs and schemas
52-
for catalog_name in this.catalog_list.catalog_names() {
53-
if let Some(catalog_schema_names) = this.catalog_list.schema_names(&catalog_name) {
52+
for catalog_name in this.catalog_list.catalog_names()? {
53+
if let Some(catalog_schema_names) = this.catalog_list.schema_names(&catalog_name)? {
5454
for schema_name in catalog_schema_names {
5555
if let Some(catalog_table_names) =
56-
this.catalog_list.table_names(&catalog_name, &schema_name)
56+
this.catalog_list.table_names(&catalog_name, &schema_name)?
5757
{
5858
// Now process all tables in this schema
5959
for table_name in catalog_table_names {

0 commit comments

Comments
 (0)