From b9c2f9ee5658125d4b510be62d8f57304564cb3c Mon Sep 17 00:00:00 2001
From: Jack Wright <56345+ayax79@users.noreply.github.com>
Date: Fri, 12 Apr 2024 07:23:46 -0700
Subject: [PATCH] displaying span information, creation time, and size with
polars ls (#12472)
# Description
`polars ls` is already different that `dfr ls`. Currently it just shows
the cache key, columns, rows, and type. I have added:
- creation time
- size
- span contents
- span start and end
# Tests + Formatting
Done
Co-authored-by: Jack Wright
---
crates/nu_plugin_polars/src/cache.rs | 43 +++++--
.../src/dataframe/eager/list.rs | 117 +++++++++++-------
.../src/dataframe/lazy/collect.rs | 6 +-
.../src/dataframe/lazy/to_lazy.rs | 2 +-
.../src/dataframe/values/mod.rs | 6 +-
.../values/nu_dataframe/custom_value.rs | 6 +-
.../values/nu_expression/custom_value.rs | 14 +--
crates/nu_plugin_polars/src/lib.rs | 7 +-
8 files changed, 128 insertions(+), 73 deletions(-)
diff --git a/crates/nu_plugin_polars/src/cache.rs b/crates/nu_plugin_polars/src/cache.rs
index a1763fbba2..d295f449a9 100644
--- a/crates/nu_plugin_polars/src/cache.rs
+++ b/crates/nu_plugin_polars/src/cache.rs
@@ -3,19 +3,28 @@ use std::{
sync::{Mutex, MutexGuard},
};
+use chrono::{DateTime, FixedOffset, Local};
use nu_plugin::EngineInterface;
-use nu_protocol::{LabeledError, ShellError};
+use nu_protocol::{LabeledError, ShellError, Span};
use uuid::Uuid;
use crate::{plugin_debug, values::PolarsPluginObject, PolarsPlugin};
+#[derive(Debug, Clone)]
+pub struct CacheValue {
+ pub uuid: Uuid,
+ pub value: PolarsPluginObject,
+ pub created: DateTime,
+ pub span: Span,
+}
+
#[derive(Default)]
pub struct Cache {
- cache: Mutex>,
+ cache: Mutex>,
}
impl Cache {
- fn lock(&self) -> Result>, ShellError> {
+ fn lock(&self) -> Result>, ShellError> {
self.cache.lock().map_err(|e| ShellError::GenericError {
error: format!("error acquiring cache lock: {e}"),
msg: "".into(),
@@ -31,7 +40,7 @@ impl Cache {
&self,
maybe_engine: Option<&EngineInterface>,
uuid: &Uuid,
- ) -> Result