use crate::table::Table;
use arrow::datatypes::SchemaRef;
use async_trait::async_trait;
use datafusion::catalog::Session;
use datafusion::datasource::TableProvider;
use datafusion::logical_expr::{Expr, TableType};
use datafusion::physical_plan::ExecutionPlan;
use std::any::Any;
use std::sync::Arc;
#[derive(Debug)]
pub struct SuperTableProvider {
table: Table,
}
impl SuperTableProvider {
pub fn new(table: Table) -> Self {
Self { table }
}
}
#[async_trait]
impl TableProvider for SuperTableProvider {
fn as_any(&self) -> &dyn Any {
self
}
fn schema(&self) -> SchemaRef {
self.table.metadata.current_schema().to_arrow_schema_ref()
}
fn table_type(&self) -> TableType {
TableType::Base
}
async fn scan(
&self,
_state: &dyn Session,
_projection: Option<&Vec<usize>>,
_filters: &[Expr],
_limit: Option<usize>,
) -> datafusion::error::Result<Arc<dyn ExecutionPlan>> {
let snapshot = self.table.metadata.current_snapshot().ok_or_else(|| {
datafusion::error::DataFusionError::Plan("No current snapshot found".to_string())
})?;
let _files = snapshot
.all_data_files(&self.table.storage)
.await
.map_err(|e| datafusion::error::DataFusionError::External(e.into()))?;
Err(datafusion::error::DataFusionError::NotImplemented(
"Physical scan execution requires further integration with DataFusion's ParquetExec"
.to_string(),
))
}
}