Skip to content

Commit

Permalink
imply debug for CacheManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Ted-Jiang committed Sep 16, 2023
1 parent aaa912d commit c5c162a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 0 additions & 4 deletions datafusion/core/src/datasource/listing/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,6 @@ mod tests {
use arrow::record_batch::RecordBatch;
use datafusion_common::assert_contains;
use datafusion_common::GetExt;
use datafusion_execution::cache::cache_manager::CacheManagerConfig;
use datafusion_execution::cache::cache_unit;
use datafusion_execution::cache::cache_unit::DefaultFileStatisticsCache;
use datafusion_execution::runtime_env::{RuntimeConfig, RuntimeEnv};
use datafusion_expr::LogicalPlanBuilder;
use rstest::*;
use std::collections::HashMap;
Expand Down
7 changes: 7 additions & 0 deletions datafusion/execution/src/cache/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::cache::CacheAccessor;
use datafusion_common::{Result, Statistics};
use object_store::path::Path;
use object_store::ObjectMeta;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;

/// The cache of listing files statistics.
Expand All @@ -28,6 +29,12 @@ use std::sync::Arc;
pub type FileStatisticsCache =
Arc<dyn CacheAccessor<Path, Arc<Statistics>, Extra = ObjectMeta>>;

impl Debug for dyn CacheAccessor<Path, Arc<Statistics>, Extra = ObjectMeta> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Cache name: {} with length: {}", self.name(), self.len())
}
}

#[derive(Default)]
pub struct CacheManager {
file_statistic_cache: Option<FileStatisticsCache>,
Expand Down
3 changes: 3 additions & 0 deletions datafusion/execution/src/cache/cache_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ impl CacheAccessor<Path, Arc<Statistics>> for DefaultFileStatisticsCache {
fn clear(&self) {
self.statistics.clear()
}
fn name(&self) -> String {
"DefaultFileStatisticsCache".to_string()
}
}

#[cfg(test)]
Expand Down
4 changes: 3 additions & 1 deletion datafusion/execution/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub trait CacheAccessor<K, V>: Send + Sync {
fn is_empty(&self) -> bool {
self.len() == 0
}
/// Removes all entries from the cache.
/// Remove all entries from the cache.
fn clear(&self);
/// Return the cache name.
fn name(&self) -> String;
}

0 comments on commit c5c162a

Please sign in to comment.