From 4fdfd3d15e6a717eb230d419b1a622e4643abd38 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 16 Sep 2022 08:34:58 -0500 Subject: [PATCH] rename with_sql to query dfr (#6568) * rename with_sql to query dfr * add search terms * update example command --- crates/nu-command/src/dataframe/eager/mod.rs | 8 ++++---- .../eager/{with_sql.rs => query_dfr.rs} | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) rename crates/nu-command/src/dataframe/eager/{with_sql.rs => query_dfr.rs} (88%) diff --git a/crates/nu-command/src/dataframe/eager/mod.rs b/crates/nu-command/src/dataframe/eager/mod.rs index 80421f77f9..ea865ff3f6 100644 --- a/crates/nu-command/src/dataframe/eager/mod.rs +++ b/crates/nu-command/src/dataframe/eager/mod.rs @@ -13,6 +13,7 @@ mod last; mod list; mod melt; mod open; +mod query_dfr; mod rename; mod sample; mod shape; @@ -26,7 +27,6 @@ mod to_df; mod to_nu; mod to_parquet; mod with_column; -mod with_sql; use nu_protocol::engine::StateWorkingSet; @@ -45,6 +45,7 @@ pub use last::LastDF; pub use list::ListDF; pub use melt::MeltDF; pub use open::OpenDataFrame; +pub use query_dfr::QueryDfr; pub use rename::RenameDF; pub use sample::SampleDF; pub use shape::ShapeDF; @@ -58,7 +59,6 @@ pub use to_df::ToDataFrame; pub use to_nu::ToNu; pub use to_parquet::ToParquet; pub use with_column::WithColumn; -pub use with_sql::WithSql; pub fn add_eager_decls(working_set: &mut StateWorkingSet) { macro_rules! bind_command { @@ -87,6 +87,7 @@ pub fn add_eager_decls(working_set: &mut StateWorkingSet) { ListDF, MeltDF, OpenDataFrame, + QueryDfr, RenameDF, SampleDF, ShapeDF, @@ -97,7 +98,6 @@ pub fn add_eager_decls(working_set: &mut StateWorkingSet) { ToDataFrame, ToNu, ToParquet, - WithColumn, - WithSql + WithColumn ); } diff --git a/crates/nu-command/src/dataframe/eager/with_sql.rs b/crates/nu-command/src/dataframe/eager/query_dfr.rs similarity index 88% rename from crates/nu-command/src/dataframe/eager/with_sql.rs rename to crates/nu-command/src/dataframe/eager/query_dfr.rs index 90abfeacaf..33f967f827 100644 --- a/crates/nu-command/src/dataframe/eager/with_sql.rs +++ b/crates/nu-command/src/dataframe/eager/query_dfr.rs @@ -14,15 +14,15 @@ use nu_protocol::{ // https://github.com/pola-rs/polars/tree/master/polars-sql #[derive(Clone)] -pub struct WithSql; +pub struct QueryDfr; -impl Command for WithSql { +impl Command for QueryDfr { fn name(&self) -> &str { - "with-sql" + "query dfr" } fn usage(&self) -> &str { - "Query dataframe using SQL. Note: The dataframe is always named df in your query." + "Query dataframe using SQL. Note: The dataframe is always named 'df' in your query's from clause." } fn signature(&self) -> Signature { @@ -33,10 +33,14 @@ impl Command for WithSql { .category(Category::Custom("dataframe".into())) } + fn search_terms(&self) -> Vec<&str> { + vec!["dataframe", "sql", "search"] + } + fn examples(&self) -> Vec { vec![Example { description: "Query dataframe using SQL", - example: "[[a b]; [1 2] [3 4]] | into df | with-sql 'select a from df'", + example: "[[a b]; [1 2] [3 4]] | into df | query dfr 'select a from df'", result: Some( NuDataFrame::try_from_columns(vec![Column::new( "a".to_string(), @@ -97,6 +101,6 @@ mod test { #[test] fn test_examples() { - test_dataframe(vec![Box::new(WithSql {})]) + test_dataframe(vec![Box::new(QueryDfr {})]) } }