diff --git a/AGENTS.md b/AGENTS.md
index ea33c41..91f5c51 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -77,10 +77,10 @@ The playground config holds `[[catalogs]]` entries with `name`, `type` (`rest` o
### Catalog → schema → table
-`IcebergCatalogProvider::catalog_builder(client)` discovers namespaces and table names at construction. `with_fixed_tables` supplies the names locally and allows appends with fixed membership. `static_builder()` accepts detached tables and historical snapshots and builds a read-only catalog synchronously.
+`IcebergCatalogProvider::catalog_builder(client)` discovers namespaces and table names at construction. Namespaces stay fixed, but table lookups, `CREATE TABLE` and `DROP TABLE` ask the catalog, so they see tables other clients create or drop later; the listed names only serve listings. `with_fixed_tables` supplies the names locally and allows appends with fixed membership. `static_builder()` accepts detached tables and historical snapshots and builds a read-only catalog synchronously.
- Names like `
$snapshots`, `$manifests`, and `$history` resolve to `IcebergMetadataTableProvider`.
-- SQL `CREATE TABLE` and `DROP TABLE` reach the *synchronous* `SchemaProvider::register_table` and `deregister_table` methods, which call the async catalog through `spawn_blocking` + `block_on`. `register_table` rejects input tables that contain rows, so CTAS isn't supported. It auto-assigns field IDs and uses format V2 unless the schema needs V3.
+- SQL `CREATE TABLE` and `DROP TABLE` reach the *synchronous* `SchemaProvider::register_table` and `deregister_table` methods, which call the async catalog through `spawn_blocking` + `block_on`. Both reject names containing `$`, which lookups read as metadata tables. `register_table` rejects input tables that contain rows, so CTAS isn't supported. It auto-assigns field IDs and uses format V2 unless the schema needs V3.
### Table providers (`table_provider/`)
diff --git a/crates/datafusion/src/catalog/provider.rs b/crates/datafusion/src/catalog/provider.rs
index 9b0c895..16539a9 100644
--- a/crates/datafusion/src/catalog/provider.rs
+++ b/crates/datafusion/src/catalog/provider.rs
@@ -36,7 +36,8 @@ pub struct IcebergCatalogProvider {
impl IcebergCatalogProvider {
/// Starts a live catalog builder with a REST client, in-memory catalog, or caching wrapper.
- /// By default, building the provider discovers namespaces and table names.
+ /// By default, building the provider discovers namespaces and table names;
+ /// tables other clients create or drop later are found by name when queried.
pub fn catalog_builder(catalog: Arc) -> IcebergCatalogProviderBuilder {
IcebergCatalogProviderBuilder {
catalog,
diff --git a/crates/datafusion/src/catalog/schema.rs b/crates/datafusion/src/catalog/schema.rs
index 40492e6..546bfa2 100644
--- a/crates/datafusion/src/catalog/schema.rs
+++ b/crates/datafusion/src/catalog/schema.rs
@@ -22,7 +22,7 @@ use dashmap::DashMap;
use datafusion::catalog::SchemaProvider;
use datafusion::common::{
config_err, exec_datafusion_err, exec_err, not_impl_datafusion_err,
- plan_datafusion_err,
+ plan_datafusion_err, plan_err,
};
use datafusion::datasource::TableProvider;
use datafusion::error::Result;
@@ -33,7 +33,7 @@ use iceberg::arrow::arrow_schema_to_schema_auto_assign_ids;
use iceberg::inspect::MetadataTableType;
use iceberg::spec::FormatVersion;
use iceberg::table::Table;
-use iceberg::{Catalog, NamespaceIdent, TableCreation, TableIdent};
+use iceberg::{Catalog, ErrorKind, NamespaceIdent, TableCreation, TableIdent};
use crate::metadata::IcebergMetadataTableProvider;
use crate::table_provider::IcebergTableProvider;
@@ -43,7 +43,12 @@ use crate::to_datafusion_error;
#[derive(Debug)]
pub(crate) struct IcebergSchemaProvider {
pub(super) namespace: NamespaceIdent,
- ddl_catalog: Option>,
+ /// The catalog this namespace mirrors: lookups of names missing from
+ /// `tables`, and DDL, go to it. `None` for a fixed set of tables.
+ catalog: Option>,
+ /// The tables when the namespace was built, updated by DDL through it but
+ /// not by other clients. With `catalog` set, only `table_names` and
+ /// `table_exist` rely on it.
tables: Arc>,
}
@@ -58,7 +63,7 @@ impl IcebergSchemaProvider {
pub(super) fn fixed(namespace: NamespaceIdent) -> Self {
Self {
namespace,
- ddl_catalog: None,
+ catalog: None,
tables: Arc::default(),
}
}
@@ -72,7 +77,7 @@ impl IcebergSchemaProvider {
.await
.map_err(to_datafusion_error)?;
let schema = Self {
- ddl_catalog: Some(catalog.clone()),
+ catalog: Some(catalog.clone()),
..Self::fixed(namespace)
};
for id in tables {
@@ -102,7 +107,7 @@ impl IcebergSchemaProvider {
}
fn catalog_for_ddl(&self) -> Result> {
- self.ddl_catalog.clone().ok_or_else(|| {
+ self.catalog.clone().ok_or_else(|| {
not_impl_datafusion_err!(
"Cannot change membership of a fixed Iceberg table registration in {}",
self.namespace
@@ -148,13 +153,21 @@ impl SchemaProvider for IcebergSchemaProvider {
}
None => (name, None),
};
- let Some(entry) = self.tables.get(table_name).map(|e| e.value().clone()) else {
- return Ok(None);
+ // Another client may have created the table after the listing, so ask
+ // the catalog unless the set is fixed.
+ let entry = match self.tables.get(table_name) {
+ Some(entry) => entry.value().clone(),
+ None => match &self.catalog {
+ Some(catalog) => Registration::Live(catalog.clone()),
+ None => return Ok(None),
+ },
};
let provider: Arc = match entry {
Registration::Live(catalog) => {
let id = TableIdent::new(self.namespace.clone(), table_name.into());
- let table = catalog.load_table(&id).await.map_err(to_datafusion_error)?;
+ let Some(table) = load_if_exists(catalog.as_ref(), &id).await? else {
+ return Ok(None);
+ };
match metadata_table_type {
Some(kind) => {
Arc::new(IcebergMetadataTableProvider::try_new(table, kind)?)
@@ -181,10 +194,7 @@ impl SchemaProvider for IcebergSchemaProvider {
table: Arc,
) -> Result