Skip to content

Commit 4b61a70

Browse files
authored
Merge pull request JanKaul#147 from splitgraph/rest-catalog-tabular-exists
Fix negative return value for RestCatalog::tabular_exists
2 parents 129c819 + 90c761c commit 4b61a70

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

catalogs/iceberg-rest-catalog/src/catalog.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl Catalog for RestCatalog {
199199
}
200200
/// Check if a table exists
201201
async fn tabular_exists(&self, identifier: &Identifier) -> Result<bool, Error> {
202-
catalog_api_api::view_exists(
202+
match catalog_api_api::view_exists(
203203
&self.configuration,
204204
self.name.as_deref(),
205205
&identifier.namespace().to_string(),
@@ -215,8 +215,11 @@ impl Catalog for RestCatalog {
215215
.await
216216
})
217217
.await
218-
.map(|_| true)
219-
.map_err(Into::<Error>::into)
218+
.map_err(Into::<Error>::into) {
219+
Ok(_) => Ok(true),
220+
Err(Error::NotFound(_)) => Ok(false),
221+
Err(e) => Err(e),
222+
}
220223
}
221224
/// Drop a table and delete all data and metadata files.
222225
async fn drop_table(&self, identifier: &Identifier) -> Result<(), Error> {
@@ -747,6 +750,21 @@ pub mod tests {
747750
.expect("Failed to list Tables");
748751
assert_eq!(tables[0].to_string(), "tpch.lineitem".to_owned());
749752

753+
assert_eq!(
754+
iceberg_catalog
755+
.tabular_exists(&Identifier::new(&["tpch".to_owned()], "lineitem"))
756+
.await
757+
.map_err(|s| s.to_string()),
758+
Ok(true)
759+
);
760+
assert_eq!(
761+
iceberg_catalog
762+
.tabular_exists(&Identifier::new(&["tpch".to_owned()], "non_existing_table"))
763+
.await
764+
.map_err(|s| s.to_string()),
765+
Ok(false)
766+
);
767+
750768
let sql = "insert into warehouse.tpch.lineitem select * from lineitem;";
751769

752770
let plan = ctx.state().create_logical_plan(sql).await.unwrap();

0 commit comments

Comments
 (0)