|
1 | | -use crate::df_error; |
2 | 1 | use crate::snowflake_table::CaseInsensitiveTable; |
3 | 2 | use crate::table::{CachingTable, IcebergTableBuilder}; |
| 3 | +use crate::{block_on_without_deadlock, df_error}; |
4 | 4 | use async_trait::async_trait; |
5 | 5 | use dashmap::DashMap; |
6 | 6 | use datafusion::catalog::{SchemaProvider, TableProvider}; |
7 | 7 | use datafusion_common::DataFusionError; |
8 | 8 | use datafusion_expr::TableType; |
9 | 9 | use datafusion_iceberg::DataFusionTable; |
10 | | -use futures::executor::block_on; |
11 | 10 | use iceberg_rust::catalog::Catalog; |
12 | 11 | use iceberg_rust::catalog::tabular::Tabular as IcebergTabular; |
13 | 12 | use iceberg_rust_spec::identifier::Identifier; |
14 | 13 | use snafu::ResultExt; |
15 | | -use snafu::futures::TryFutureExt; |
16 | 14 | use std::any::Any; |
17 | 15 | use std::sync::Arc; |
18 | 16 |
|
@@ -89,11 +87,15 @@ impl SchemaProvider for CachingSchema { |
89 | 87 | && let Some(iceberg_builder) = table.as_any().downcast_ref::<IcebergTableBuilder>() |
90 | 88 | && table.table_type() != TableType::View |
91 | 89 | { |
92 | | - let ident = Identifier::new(std::slice::from_ref(&self.name), &name); |
93 | | - block_on(async move { |
94 | | - let mut builder = iceberg_builder.builder.clone(); |
| 90 | + let catalog = Arc::clone(catalog); |
| 91 | + let mut builder = iceberg_builder.builder.clone(); |
| 92 | + let namespace = vec![self.name.clone()]; |
| 93 | + let table_name = name.clone(); |
| 94 | + |
| 95 | + block_on_without_deadlock(async move { |
| 96 | + let ident = Identifier::new(&namespace, &table_name); |
95 | 97 | let iceberg_table = builder |
96 | | - .build(ident.namespace(), catalog.clone()) |
| 98 | + .build(ident.namespace(), catalog) |
97 | 99 | .await |
98 | 100 | .context(df_error::IcebergSnafu)?; |
99 | 101 | let tabular = IcebergTabular::Table(iceberg_table); |
@@ -121,8 +123,17 @@ impl SchemaProvider for CachingSchema { |
121 | 123 | if let Some((_, caching_table)) = table { |
122 | 124 | if caching_table.table_type() != TableType::View { |
123 | 125 | if let Some(catalog) = &self.iceberg_catalog { |
124 | | - let ident = Identifier::new(std::slice::from_ref(&self.name), name); |
125 | | - block_on(catalog.drop_table(&ident).context(df_error::IcebergSnafu))?; |
| 126 | + let catalog = Arc::clone(catalog); |
| 127 | + let namespace = vec![self.name.clone()]; |
| 128 | + let table_name = name.to_string(); |
| 129 | + |
| 130 | + block_on_without_deadlock(async move { |
| 131 | + let ident = Identifier::new(&namespace, &table_name); |
| 132 | + catalog |
| 133 | + .drop_table(&ident) |
| 134 | + .await |
| 135 | + .context(df_error::IcebergSnafu) |
| 136 | + })?; |
126 | 137 | } else { |
127 | 138 | return self.schema.deregister_table(name); |
128 | 139 | } |
|
0 commit comments