alexanderbianchi commented on code in PR #116:
URL:
https://github.com/apache/datafusion-iceberg/pull/116#discussion_r4758846521
##########
crates/datafusion/src/catalog/schema.rs:
##########
@@ -18,85 +18,61 @@
use std::sync::Arc;
use async_trait::async_trait;
-use dashmap::DashMap;
+use dashmap::DashSet;
use datafusion::catalog::SchemaProvider;
use datafusion::common::{exec_datafusion_err, exec_err, plan_datafusion_err};
use datafusion::datasource::TableProvider;
use datafusion::error::Result;
use datafusion::execution::TaskContext;
use datafusion::prelude::SessionContext;
use futures::TryStreamExt;
-use futures::future::try_join_all;
use iceberg::arrow::arrow_schema_to_schema_auto_assign_ids;
use iceberg::inspect::MetadataTableType;
use iceberg::spec::FormatVersion;
use iceberg::{Catalog, NamespaceIdent, TableCreation, TableIdent};
+use crate::metadata::IcebergMetadataTableProvider;
use crate::table_provider::IcebergCatalogTableProvider;
use crate::to_datafusion_error;
/// Represents a [`SchemaProvider`] for the Iceberg [`Catalog`], managing
/// access to table providers within a specific namespace.
+///
+/// Each lookup loads the table from the catalog and returns a new provider, so
+/// a query sees the table's schema as it is when the query is planned.
#[derive(Debug)]
pub(crate) struct IcebergSchemaProvider {
/// Reference to the Iceberg catalog
catalog: Arc<dyn Catalog>,
/// The namespace this schema represents
namespace: NamespaceIdent,
- /// A concurrent map where keys are table names
- /// and values are dynamic references to objects implementing the
- /// [`TableProvider`] trait.
+ /// The names of the namespace's tables.
/// Wrapped in Arc to allow sharing across async boundaries in
register_table.
- tables: Arc<DashMap<String, Arc<IcebergCatalogTableProvider>>>,
+ tables: Arc<DashSet<String>>,
}
impl IcebergSchemaProvider {
/// Asynchronously tries to construct a new [`IcebergSchemaProvider`]
- /// using the given client to fetch and initialize table providers for
- /// the provided namespace in the Iceberg [`Catalog`].
- ///
- /// This method retrieves a list of table names
- /// attempts to create a table provider for each table name, and
- /// collects these providers into a `HashMap`.
+ /// for the provided namespace in the Iceberg [`Catalog`], listing the
+ /// namespace's tables.
pub(crate) async fn try_new(
client: Arc<dyn Catalog>,
namespace: NamespaceIdent,
) -> Result<Self> {
- // TODO:
- // Tables and providers should be cached based on table_name
- // if we have a cache miss; we update our internal cache & check again
- // As of right now; tables might become stale.
- let table_names: Vec<_> = client
+ // TODO: The table names are listed once, so tables created or dropped
Review Comment:
I think for this we could followup with a lazy load, if the table isn't
present we can check the client for new tables. Maybe we could expose some like
::with_fixed_tables(tables) or something. Right now we have two table providers
and schema providers I'd prefer if these were combined somehow, perhaps with a
builder pattern. All just ideas, this is a good improvement.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]