Skip to content

Commit 65f9726

Browse files
authored
feat: Expose cache hits in list_files_cache function (#23439)
## Which issue does this PR close? - Closes None. ## Rationale for this change Follow up to #22613 and #23253. Cache hits are now supported for all memory-limiting caches. Therefore it makes sense to expose them in the `list_files_cache` function the same way the `metadata_cache` and `statistics_cache` functions do it already. ## What changes are included in this PR? - Add cache hits to the `list_files_cache` function - Tests - Adapt documentation for the `list_files_cache` function ## Are these changes tested? Yes. ## Are there any user-facing changes? Yes, the `list_files_cache` function supports now cache hits but no breaking changes.
1 parent 04b19a3 commit 65f9726

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

datafusion-cli/src/functions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ impl TableFunctionImpl for ListFilesCacheFunc {
813813
DataType::List(Arc::new(metadata_field.clone())),
814814
true,
815815
),
816+
Field::new("hits", DataType::UInt64, false),
816817
]));
817818

818819
let mut table_arr = vec![];
@@ -826,6 +827,7 @@ impl TableFunctionImpl for ListFilesCacheFunc {
826827
let mut etag_arr = vec![];
827828
let mut version_arr = vec![];
828829
let mut offsets: Vec<i32> = vec![0];
830+
let mut hits_arr = vec![];
829831

830832
if let Some(list_files_cache) = self.cache_manager.get_list_files_cache() {
831833
let now = Instant::now();
@@ -851,6 +853,7 @@ impl TableFunctionImpl for ListFilesCacheFunc {
851853
}
852854
current_offset += entry.value.files.len() as i32;
853855
offsets.push(current_offset);
856+
hits_arr.push(entry.hits as u64);
854857
}
855858
}
856859

@@ -882,6 +885,7 @@ impl TableFunctionImpl for ListFilesCacheFunc {
882885
Arc::new(struct_arr),
883886
None,
884887
)),
888+
Arc::new(UInt64Array::from(hits_arr)),
885889
],
886890
)?;
887891

datafusion-cli/src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ mod tests {
810810
.collect()
811811
.await?;
812812

813-
let sql = "SELECT metadata_size_bytes, expires_in, metadata_list FROM list_files_cache()";
813+
let sql = "SELECT metadata_size_bytes, expires_in, metadata_list, hits FROM list_files_cache()";
814814
let df = ctx
815815
.sql(sql)
816816
.await?
@@ -838,16 +838,17 @@ mod tests {
838838
"filename",
839839
"file_size_bytes",
840840
"etag",
841+
"hits",
841842
])?
842843
.sort(vec![col("filename").sort(true, false)])?;
843844
let rbs = df.collect().await?;
844845
assert_snapshot!(batches_to_string(&rbs),@r"
845-
+---------------------+-----------+-----------------+------+
846-
| metadata_size_bytes | filename | file_size_bytes | etag |
847-
+---------------------+-----------+-----------------+------+
848-
| 212 | 0.parquet | 3642 | 0 |
849-
| 212 | 1.parquet | 3642 | 1 |
850-
+---------------------+-----------+-----------------+------+
846+
+---------------------+-----------+-----------------+------+------+
847+
| metadata_size_bytes | filename | file_size_bytes | etag | hits |
848+
+---------------------+-----------+-----------------+------+------+
849+
| 212 | 0.parquet | 3642 | 0 | 2 |
850+
| 212 | 1.parquet | 3642 | 1 | 2 |
851+
+---------------------+-----------+-----------------+------+------+
851852
");
852853

853854
Ok(())

docs/source/user-guide/cli/functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ The columns of the returned table are:
208208
| path | Utf8 | File path relative to the object store / filesystem root |
209209
| metadata_size_bytes | UInt64 | Size of the cached metadata in memory (not its thrift encoded form) |
210210
| expires_in | Duration(ms) | Last modified time of the file |
211+
| hits | UInt64 | Number of times the cached metadata has been accessed |
211212
| metadata_list | List(Struct) | List of metadatas, one for each file under the path. |
212213

213214
A metadata struct in the metadata_list contains the following fields:

0 commit comments

Comments
 (0)