use std::sync::Arc;
use arrow_schema::SchemaRef;
use async_trait::async_trait;
use datafusion::arrow::record_batch::RecordBatch;
use datafusion::execution::SendableRecordBatchStream;
use datafusion::logical_expr::Expr;
use crate::errors::FnError;
#[derive(Clone, Debug, Default)]
pub struct StorageOptions {
pub config_json: String,
}
#[derive(Clone, Debug)]
pub struct WriteHandle {
pub id: u64,
}
#[derive(Clone, Debug)]
pub struct BranchMetadata {
pub parent_version: u64,
pub branch_name: String,
}
#[async_trait]
pub trait StorageBackend: Send + Sync {
fn scheme(&self) -> &'static str;
async fn open(&self, uri: &str, options: &StorageOptions) -> Result<Arc<dyn Storage>, FnError>;
}
#[async_trait]
pub trait Storage: Send + Sync {
async fn read_batch(
&self,
table: &str,
predicate: Option<&Expr>,
) -> Result<SendableRecordBatchStream, FnError>;
async fn write_batch(&self, table: &str, batch: &RecordBatch) -> Result<WriteHandle, FnError>;
async fn list_tables(&self) -> Result<Vec<String>, FnError>;
async fn delete(&self, table: &str, predicate: &Expr) -> Result<u64, FnError>;
fn supports_branching(&self) -> bool {
false
}
async fn fork(
&self,
_table: &str,
_src_branch: &str,
_dst_branch: &str,
) -> Result<BranchMetadata, FnError> {
Err(FnError::new(
0x10,
"storage backend does not support branching",
))
}
async fn schema(&self, _table: &str) -> Option<SchemaRef> {
None
}
}