-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use parquet lru reader as trait object
- Loading branch information
Showing
17 changed files
with
206 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,56 @@ | ||
mod r#dyn; | ||
Check failure on line 1 in parquet-lru/src/lib.rs GitHub Actions / check
|
||
#[cfg(feature = "foyer")] | ||
pub mod foyer; | ||
|
||
use std::{future::Future, marker::PhantomData}; | ||
|
||
use parquet::{arrow::async_reader::AsyncFileReader, errors::Result}; | ||
use thiserror::Error; | ||
use parquet::arrow::async_reader::AsyncFileReader; | ||
|
||
#[derive(Default)] | ||
pub struct Options { | ||
meta_capacity: usize, | ||
data_capacity: usize, | ||
} | ||
|
||
impl Options { | ||
pub fn meta_capacity(mut self, meta_capacity: usize) -> Self { | ||
self.meta_capacity = meta_capacity; | ||
self | ||
} | ||
|
||
pub fn data_capacity(mut self, data_capacity: usize) -> Self { | ||
self.data_capacity = data_capacity; | ||
self | ||
} | ||
} | ||
pub use crate::r#dyn::*; | ||
Check warning on line 9 in parquet-lru/src/lib.rs GitHub Actions / check
|
||
|
||
pub trait LruCache<K>: Clone + Send + Sync + 'static { | ||
type LruReader<R: AsyncFileReader + 'static>: AsyncFileReader + 'static; | ||
|
||
fn new(options: Options) -> impl Future<Output = Result<Self, Error>> + Send; | ||
pub trait LruCache<K> | ||
where | ||
K: 'static, | ||
{ | ||
type LruReader<R>: AsyncFileReader + 'static | ||
where | ||
R: AsyncFileReader + 'static; | ||
|
||
fn get_reader<R>(&self, key: K, reader: R) -> impl Future<Output = Self::LruReader<R>> + Send | ||
where | ||
R: AsyncFileReader + 'static; | ||
} | ||
|
||
#[derive(Clone, Default)] | ||
pub struct NoopCache<K> { | ||
#[derive(Default)] | ||
pub struct NoCache<K> { | ||
_phantom: PhantomData<K>, | ||
} | ||
|
||
impl<K> LruCache<K> for NoopCache<K> | ||
where | ||
K: Send + Sync + Clone + 'static, | ||
{ | ||
type LruReader<R: AsyncFileReader + 'static> = R; | ||
|
||
async fn new(_options: Options) -> Result<Self, Error> { | ||
Ok(Self { | ||
impl<K> Clone for NoCache<K> { | ||
fn clone(&self) -> Self { | ||
Self { | ||
_phantom: PhantomData, | ||
}) | ||
} | ||
|
||
async fn get_reader<R: AsyncFileReader>(&self, _key: K, reader: R) -> R { | ||
reader | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("External lru implementation error: {0}")] | ||
External(#[from] Box<dyn std::error::Error + Send + Sync + 'static>), | ||
unsafe impl<K> Send for NoCache<K> {} | ||
|
||
unsafe impl<K> Sync for NoCache<K> {} | ||
|
||
impl<K> LruCache<K> for NoCache<K> | ||
where | ||
K: 'static, | ||
{ | ||
type LruReader<R> = R | ||
where | ||
R: AsyncFileReader + 'static; | ||
|
||
#[allow(clippy::manual_async_fn)] | ||
fn get_reader<R>(&self, _key: K, reader: R) -> impl Future<Output = R> + Send | ||
where | ||
R: AsyncFileReader, | ||
{ | ||
async move { reader } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.