-
Notifications
You must be signed in to change notification settings - Fork 140
chore: datafusion 52.1.0 #1174
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
Merged
chore: datafusion 52.1.0 #1174
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c16300f
update
lonless9 301e98f
upgrade
lonless9 d983e25
fix
lonless9 3f2485a
update
lonless9 b8217f8
update
lonless9 e56622c
update
lonless9 e5298c7
update
lonless9 7564ea6
update
lonless9 2d03c5a
clippy
lonless9 efbd463
update
lonless9 645648a
base
lonless9 260b10d
merge
lonless9 514462b
[spark tests]
lonless9 75b2750
update
lonless9 3dfe014
fix
lonless9 c35c1ae
clippy
lonless9 3481deb
fix cargo test
lonless9 0033a19
merge
lonless9 11f41e8
update
lonless9 6f2724d
revert
lonless9 8499471
clippy
lonless9 656b8df
Merge remote-tracking branch 'origin/main' into df-52
lonless9 363b066
update
lonless9 85dcff4
bump version
lonless9 95b836a
merge main
lonless9 48f7626
update snapshot
lonless9 da1d2f8
update
lonless9 d4583fe
remove dbg
lonless9 f5cfcf3
fmt
lonless9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,14 +1,20 @@ | ||
| use std::collections::HashMap; | ||
| use std::mem::size_of; | ||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
|
|
||
| use datafusion::execution::cache::CacheAccessor; | ||
| use datafusion::common::{Result as DataFusionResult, TableReference}; | ||
| use datafusion::execution::cache::cache_manager::ListFilesCache; | ||
| use datafusion::execution::cache::{CacheAccessor, ListFilesEntry, TableScopedPath}; | ||
| use log::debug; | ||
| use moka::sync::Cache; | ||
| use object_store::path::Path; | ||
| use object_store::ObjectMeta; | ||
|
|
||
| pub struct MokaFileListingCache { | ||
| objects: Cache<Path, Arc<Vec<ObjectMeta>>>, | ||
| objects: Cache<TableScopedPath, Arc<Vec<ObjectMeta>>>, | ||
| ttl: Option<Duration>, | ||
| max_entries: Option<u64>, | ||
| } | ||
|
|
||
| impl MokaFileListingCache { | ||
|
|
@@ -17,9 +23,10 @@ impl MokaFileListingCache { | |
| pub fn new(ttl: Option<u64>, max_entries: Option<u64>) -> Self { | ||
| let mut builder = Cache::builder(); | ||
|
|
||
| let ttl = ttl.map(Duration::from_secs); | ||
| if let Some(ttl) = ttl { | ||
| debug!("Setting TTL for {} to {ttl} second(s)", Self::NAME); | ||
| builder = builder.time_to_live(Duration::from_secs(ttl)); | ||
| debug!("Setting TTL for {} to {:?} second(s)", Self::NAME, ttl); | ||
|
linhr marked this conversation as resolved.
|
||
| builder = builder.time_to_live(ttl); | ||
| } | ||
| if let Some(max_entries) = max_entries { | ||
| debug!( | ||
|
|
@@ -31,40 +38,87 @@ impl MokaFileListingCache { | |
|
|
||
| Self { | ||
| objects: builder.build(), | ||
| ttl, | ||
| max_entries, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl CacheAccessor<Path, Arc<Vec<ObjectMeta>>> for MokaFileListingCache { | ||
| type Extra = ObjectMeta; | ||
| /// Calculates the number of bytes an [`ObjectMeta`] occupies in the heap. | ||
| fn meta_heap_bytes(object_meta: &ObjectMeta) -> usize { | ||
| let mut size = object_meta.location.as_ref().len(); | ||
|
|
||
| fn get(&self, k: &Path) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| self.objects.get(k) | ||
| if let Some(e) = &object_meta.e_tag { | ||
| size += e.len(); | ||
| } | ||
| if let Some(v) = &object_meta.version { | ||
| size += v.len(); | ||
| } | ||
|
|
||
| size | ||
| } | ||
|
|
||
| impl CacheAccessor<TableScopedPath, Arc<Vec<ObjectMeta>>> for MokaFileListingCache { | ||
| type Extra = Option<Path>; | ||
|
|
||
| fn get(&self, k: &TableScopedPath) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| self.get_with_extra(k, &None) | ||
| } | ||
|
|
||
| fn get_with_extra( | ||
| &self, | ||
| k: &TableScopedPath, | ||
| prefix: &Self::Extra, | ||
| ) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| let objects = self.objects.get(k)?; | ||
|
|
||
| let Some(prefix) = prefix else { | ||
| return Some(objects); | ||
| }; | ||
|
|
||
| fn get_with_extra(&self, k: &Path, _e: &Self::Extra) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| self.get(k) | ||
| // Build full prefix: table_base/prefix | ||
| let table_base = &k.path; | ||
| let mut parts: Vec<_> = table_base.parts().collect(); | ||
| parts.extend(prefix.parts()); | ||
| let full_prefix = Path::from_iter(parts); | ||
| let full_prefix_str = full_prefix.as_ref(); | ||
|
|
||
| let filtered = objects | ||
| .iter() | ||
| .filter(|meta| meta.location.as_ref().starts_with(full_prefix_str)) | ||
| .cloned() | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| if filtered.is_empty() { | ||
| None | ||
| } else { | ||
| Some(Arc::new(filtered)) | ||
| } | ||
| } | ||
|
|
||
| fn put(&self, key: &Path, value: Arc<Vec<ObjectMeta>>) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| fn put( | ||
| &self, | ||
| key: &TableScopedPath, | ||
| value: Arc<Vec<ObjectMeta>>, | ||
| ) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| self.objects.insert(key.clone(), value); | ||
| None | ||
| } | ||
|
|
||
| fn put_with_extra( | ||
| &self, | ||
| key: &Path, | ||
| key: &TableScopedPath, | ||
| value: Arc<Vec<ObjectMeta>>, | ||
| _e: &Self::Extra, | ||
| ) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| self.put(key, value) | ||
| } | ||
|
|
||
| fn remove(&mut self, k: &Path) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| fn remove(&self, k: &TableScopedPath) -> Option<Arc<Vec<ObjectMeta>>> { | ||
| self.objects.remove(k) | ||
| } | ||
|
|
||
| fn contains_key(&self, k: &Path) -> bool { | ||
| fn contains_key(&self, k: &TableScopedPath) -> bool { | ||
| self.objects.contains_key(k) | ||
| } | ||
|
|
||
|
|
@@ -81,11 +135,64 @@ impl CacheAccessor<Path, Arc<Vec<ObjectMeta>>> for MokaFileListingCache { | |
| } | ||
| } | ||
|
|
||
| impl ListFilesCache for MokaFileListingCache { | ||
| fn cache_limit(&self) -> usize { | ||
| self.max_entries | ||
| .map(|limit| limit as usize) | ||
| .unwrap_or(usize::MAX) | ||
| } | ||
|
|
||
| fn cache_ttl(&self) -> Option<Duration> { | ||
| self.ttl | ||
| } | ||
|
|
||
| fn update_cache_limit(&self, _limit: usize) { | ||
| // TODO: support dynamic update of cache limit | ||
| } | ||
|
|
||
| fn update_cache_ttl(&self, _ttl: Option<Duration>) { | ||
| // TODO: support dynamic update of cache ttl | ||
| } | ||
|
Comment on lines
+149
to
+155
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moka likely does not support this option, and refactoring here to use locks for protection doesn't seem like a good idea either. So I guess we can leave it as a TODO for now. |
||
|
|
||
| fn list_entries(&self) -> HashMap<TableScopedPath, ListFilesEntry> { | ||
| self.objects | ||
| .iter() | ||
| .map(|(table_scoped_path, metas)| { | ||
| let metas = Arc::clone(&metas); | ||
| let size_bytes = (metas.capacity() * size_of::<ObjectMeta>()) | ||
| + metas.iter().map(meta_heap_bytes).sum::<usize>(); | ||
| ( | ||
| (*table_scoped_path).clone(), | ||
| ListFilesEntry { | ||
| metas, | ||
| size_bytes, | ||
| // moka handles expiration; we don't have per-entry expiration time | ||
| expires: None, | ||
| }, | ||
| ) | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| fn drop_table_entries(&self, table_ref: &Option<TableReference>) -> DataFusionResult<()> { | ||
| let keys_to_drop: Vec<TableScopedPath> = self | ||
| .objects | ||
| .iter() | ||
| .filter_map(|(k, _v)| (k.table == *table_ref).then_some((*k).clone())) | ||
| .collect(); | ||
|
|
||
| for key in keys_to_drop { | ||
| self.objects.invalidate(&key); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[allow(clippy::unwrap_used)] | ||
| #[cfg(test)] | ||
| mod tests { | ||
| use chrono::DateTime; | ||
| use object_store::path::Path; | ||
| use object_store::ObjectMeta; | ||
|
|
||
| use super::*; | ||
|
|
@@ -103,11 +210,15 @@ mod tests { | |
| }; | ||
|
|
||
| let cache = MokaFileListingCache::new(None, None); | ||
| assert!(cache.get(&meta.location).is_none()); | ||
| let key = TableScopedPath { | ||
| table: None, | ||
| path: meta.location.clone(), | ||
| }; | ||
| assert!(cache.get(&key).is_none()); | ||
|
|
||
| cache.put(&meta.location, vec![meta.clone()].into()); | ||
| cache.put(&key, vec![meta.clone()].into()); | ||
| assert_eq!( | ||
| cache.get(&meta.location).unwrap().first().unwrap().clone(), | ||
| cache.get(&key).unwrap().first().unwrap().clone(), | ||
| meta.clone() | ||
| ); | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to later change all imports of session from
datafusion-catalogto imports fromdatafusion-session.