Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New method DeltaReader::get_smallest[_async] #17

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/cache/delta_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ impl DeltaReader {
tokio::task::block_in_place(|| self.get(key))
}

/// Get the value of the smallest key written value for given [`Schema`].
pub fn get_smallest<S: Schema>(&self) -> anyhow::Result<Option<(S::Key, S::Value)>> {
let mut iterator = self.iter::<S>()?;
if let Some((key, value)) = iterator.next() {
let key = S::Key::decode_key(&key)?;
let value = S::Value::decode_value(&value)?;
return Ok(Some((key, value)));
}
Ok(None)
}

/// Async version of [`DeltaReader::get_smallest`].
pub async fn get_smallest_async<S: Schema>(
&self,
) -> anyhow::Result<Option<(S::Key, S::Value)>> {
tokio::task::block_in_place(|| self.get_smallest::<S>())
}

/// Get a value of the largest key written value for given [`Schema`].
pub fn get_largest<S: Schema>(&self) -> anyhow::Result<Option<(S::Key, S::Value)>> {
let mut iterator = self.iter_rev::<S>()?;
Expand Down
Loading