use std::sync::Arc;
use crate::{DeltaFunnelError, DeltaStorageOptions};
use super::file_reader::{
DeltaFileReadRequest, DeltaFileReadResult, DeltaFileReader, DeltaFileReaderConfig,
};
use super::scheduling::DeltaProviderReaderBackend;
pub(crate) struct DeltaProviderReaderBackendConfig<'a> {
pub(crate) reader_backend: DeltaProviderReaderBackend,
pub(crate) source_name: &'a str,
pub(crate) table_uri: &'a str,
pub(crate) snapshot_version: u64,
pub(crate) storage_options: &'a DeltaStorageOptions,
}
pub(crate) trait DeltaScanPartitionFileReader: Send + Sync {
fn read_file(
&self,
request: DeltaFileReadRequest<'_>,
) -> Result<DeltaFileReadResult, DeltaFunnelError>;
}
pub(crate) fn build_partition_file_reader(
config: DeltaProviderReaderBackendConfig<'_>,
) -> Result<Arc<dyn DeltaScanPartitionFileReader>, DeltaFunnelError> {
match config.reader_backend {
DeltaProviderReaderBackend::OfficialKernel => {
let reader = DeltaFileReader::try_new(DeltaFileReaderConfig {
source_name: config.source_name,
table_uri: config.table_uri,
snapshot_version: config.snapshot_version,
storage_options: config.storage_options,
})?;
Ok(Arc::new(reader))
}
DeltaProviderReaderBackend::NativeAsync => Err(DeltaFunnelError::Config {
message:
"native async reader backend is not wired into sync partition reader execution"
.to_owned(),
}),
}
}
impl DeltaScanPartitionFileReader for DeltaFileReader {
fn read_file(
&self,
request: DeltaFileReadRequest<'_>,
) -> Result<DeltaFileReadResult, DeltaFunnelError> {
Self::read_file(self, request)
}
}