make polars commands propagate metadata

This commit is contained in:
Julian Amarilla 2025-04-25 02:31:58 -03:00
parent b8e6dde4ff
commit c071e69f5a
9 changed files with 26 additions and 33 deletions

2
Cargo.lock generated
View File

@ -3987,7 +3987,6 @@ dependencies = [
"tempfile", "tempfile",
"thiserror 2.0.6", "thiserror 2.0.6",
"typetag", "typetag",
"url",
"web-time", "web-time",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -7652,7 +7651,6 @@ dependencies = [
"form_urlencoded", "form_urlencoded",
"idna", "idna",
"percent-encoding", "percent-encoding",
"serde",
] ]
[[package]] [[package]]

View File

@ -169,7 +169,7 @@ umask = "2.1"
unicode-segmentation = "1.12" unicode-segmentation = "1.12"
unicode-width = "0.2" unicode-width = "0.2"
ureq = { version = "2.12", default-features = false, features = ["socks-proxy"] } ureq = { version = "2.12", default-features = false, features = ["socks-proxy"] }
url = { version = "2.2", features = [ "serde" ] } url = "2.2"
uu_cp = "0.0.30" uu_cp = "0.0.30"
uu_mkdir = "0.0.30" uu_mkdir = "0.0.30"
uu_mktemp = "0.0.30" uu_mktemp = "0.0.30"

View File

@ -44,7 +44,6 @@ os_pipe = { workspace = true, optional = true, features = ["io_safety"] }
log = { workspace = true } log = { workspace = true }
web-time = { workspace = true } web-time = { workspace = true }
memchr = { workspace = true } memchr = { workspace = true }
url = { workspace = true }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
nix = { workspace = true, default-features = false, features = ["signal"] } nix = { workspace = true, default-features = false, features = ["signal"] }

View File

@ -1,5 +1,4 @@
use std::path::PathBuf; use std::path::PathBuf;
use url::Url;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -35,7 +34,7 @@ pub enum DataSource {
Ls, Ls,
HtmlThemes, HtmlThemes,
FilePath(PathBuf), FilePath(PathBuf),
Url(Box<Url>), Url(String),
#[default] #[default]
None, None,
} }

View File

@ -12,9 +12,8 @@ use nu_protocol::{
shell_error::io::IoError, Category, DataSource, Example, LabeledError, PipelineData, shell_error::io::IoError, Category, DataSource, Example, LabeledError, PipelineData,
PipelineMetadata, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, PipelineMetadata, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
}; };
use url::Url;
use std::{fs::File, io::BufReader, num::NonZeroUsize, path::PathBuf, str::FromStr, sync::Arc}; use std::{fs::File, io::BufReader, num::NonZeroUsize, path::PathBuf, sync::Arc};
use polars::{ use polars::{
lazy::frame::LazyJsonLineReader, lazy::frame::LazyJsonLineReader,
@ -129,8 +128,8 @@ impl PluginCommand for OpenDataFrame {
fn run( fn run(
&self, &self,
plugin: &Self::Plugin, plugin: &Self::Plugin,
engine: &EngineInterface, engine: &nu_plugin::EngineInterface,
call: &EvaluatedCall, call: &nu_plugin::EvaluatedCall,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, LabeledError> { ) -> Result<PipelineData, LabeledError> {
let metadata = input.metadata(); let metadata = input.metadata();
@ -182,9 +181,7 @@ fn command(
let uri = spanned_file.item.clone(); let uri = spanned_file.item.clone();
let data_source = if resource.cloud_options.is_some() { let data_source = if resource.cloud_options.is_some() {
Url::from_str(&uri) DataSource::Url(uri)
.map(|url| DataSource::Url(url.into()))
.unwrap_or_else(|_| DataSource::FilePath(uri.into()))
} else { } else {
DataSource::FilePath(uri.into()) DataSource::FilePath(uri.into())
}; };

View File

@ -51,7 +51,7 @@ impl PluginCommand for CutSeries {
engine: &EngineInterface, engine: &EngineInterface,
call: &EvaluatedCall, call: &EvaluatedCall,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, LabeledError> { ) -> Result<PipelineData, nu_protocol::LabeledError> {
let metadata = input.metadata(); let metadata = input.metadata();
self.run_inner(plugin, engine, call, input) self.run_inner(plugin, engine, call, input)
.map(|pd| pd.set_metadata(metadata)) .map(|pd| pd.set_metadata(metadata))

View File

@ -52,7 +52,7 @@ impl PluginCommand for QCutSeries {
engine: &EngineInterface, engine: &EngineInterface,
call: &EvaluatedCall, call: &EvaluatedCall,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, LabeledError> { ) -> Result<PipelineData, nu_protocol::LabeledError> {
let metadata = input.metadata(); let metadata = input.metadata();
self.run_inner(plugin, engine, call, input) self.run_inner(plugin, engine, call, input)
.map(|pd| pd.set_metadata(metadata)) .map(|pd| pd.set_metadata(metadata))

View File

@ -88,6 +88,14 @@ impl PluginCommand for GetDay {
self.run_inner(plugin, engine, call, input) self.run_inner(plugin, engine, call, input)
.map(|pd| pd.set_metadata(metadata)) .map(|pd| pd.set_metadata(metadata))
} }
fn extra_description(&self) -> &str {
""
}
fn search_terms(&self) -> Vec<&str> {
vec![]
}
} }
impl GetDay { impl GetDay {
@ -100,14 +108,6 @@ impl GetDay {
) -> Result<PipelineData, LabeledError> { ) -> Result<PipelineData, LabeledError> {
command(plugin, engine, call, input).map_err(LabeledError::from) command(plugin, engine, call, input).map_err(LabeledError::from)
} }
fn extra_description(&self) -> &str {
""
}
fn search_terms(&self) -> Vec<&str> {
vec![]
}
} }
fn command( fn command(

View File

@ -154,6 +154,16 @@ impl PluginCommand for Truncate {
self.run_inner(plugin, engine, call, input) self.run_inner(plugin, engine, call, input)
.map(|pd| pd.set_metadata(metadata)) .map(|pd| pd.set_metadata(metadata))
} }
fn extra_description(&self) -> &str {
r#"Each date/datetime is mapped to the start of its bucket using the corresponding local datetime. Note that weekly buckets start on Monday. Ambiguous results are localised using the DST offset of the original timestamp - for example, truncating '2022-11-06 01:30:00 CST' by '1h' results in '2022-11-06 01:00:00 CST', whereas truncating '2022-11-06 01:30:00 CDT' by '1h' results in '2022-11-06 01:00:00 CDT'.
See Notes in documentation for full list of compatible string values for `every`: https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.dt.truncate.html"#
}
fn search_terms(&self) -> Vec<&str> {
vec![]
}
} }
impl Truncate { impl Truncate {
@ -166,16 +176,6 @@ impl Truncate {
) -> Result<PipelineData, LabeledError> { ) -> Result<PipelineData, LabeledError> {
command(plugin, engine, call, input).map_err(LabeledError::from) command(plugin, engine, call, input).map_err(LabeledError::from)
} }
fn extra_description(&self) -> &str {
r#"Each date/datetime is mapped to the start of its bucket using the corresponding local datetime. Note that weekly buckets start on Monday. Ambiguous results are localised using the DST offset of the original timestamp - for example, truncating '2022-11-06 01:30:00 CST' by '1h' results in '2022-11-06 01:00:00 CST', whereas truncating '2022-11-06 01:30:00 CDT' by '1h' results in '2022-11-06 01:00:00 CDT'.
See Notes in documentation for full list of compatible string values for `every`: https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.dt.truncate.html"#
}
fn search_terms(&self) -> Vec<&str> {
vec![]
}
} }
fn command( fn command(