|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::{any::Any, sync::Arc}; |
|
|
|
|
|
use async_trait::async_trait; |
|
|
use datafusion::error::Result as DFResult; |
|
|
use datafusion::{ |
|
|
arrow::datatypes::SchemaRef as ArrowSchemaRef, |
|
|
datasource::{TableProvider, TableType}, |
|
|
execution::context, |
|
|
logical_expr::Expr, |
|
|
physical_plan::ExecutionPlan, |
|
|
}; |
|
|
use iceberg::{ |
|
|
arrow::schema_to_arrow_schema, table::Table, Catalog, NamespaceIdent, Result, TableIdent, |
|
|
}; |
|
|
|
|
|
use crate::physical_plan::scan::IcebergTableScan; |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) struct IcebergTableProvider { |
|
|
|
|
|
table: Table, |
|
|
|
|
|
schema: ArrowSchemaRef, |
|
|
} |
|
|
|
|
|
impl IcebergTableProvider { |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn try_new( |
|
|
client: Arc<dyn Catalog>, |
|
|
namespace: NamespaceIdent, |
|
|
name: impl Into<String>, |
|
|
) -> Result<Self> { |
|
|
let ident = TableIdent::new(namespace, name.into()); |
|
|
let table = client.load_table(&ident).await?; |
|
|
|
|
|
let schema = Arc::new(schema_to_arrow_schema(table.metadata().current_schema())?); |
|
|
|
|
|
Ok(IcebergTableProvider { table, schema }) |
|
|
} |
|
|
} |
|
|
|
|
|
#[async_trait] |
|
|
impl TableProvider for IcebergTableProvider { |
|
|
fn as_any(&self) -> &dyn Any { |
|
|
self |
|
|
} |
|
|
|
|
|
fn schema(&self) -> ArrowSchemaRef { |
|
|
self.schema.clone() |
|
|
} |
|
|
|
|
|
fn table_type(&self) -> TableType { |
|
|
TableType::Base |
|
|
} |
|
|
|
|
|
async fn scan( |
|
|
&self, |
|
|
_state: &context::SessionState, |
|
|
_projection: Option<&Vec<usize>>, |
|
|
_filters: &[Expr], |
|
|
_limit: Option<usize>, |
|
|
) -> DFResult<Arc<dyn ExecutionPlan>> { |
|
|
Ok(Arc::new(IcebergTableScan::new( |
|
|
self.table.clone(), |
|
|
self.schema.clone(), |
|
|
))) |
|
|
} |
|
|
} |
|
|
|