rename with_sql to query dfr (#6568)

* rename with_sql to query dfr

* add search terms

* update example command
This commit is contained in:
Darren Schroeder 2022-09-16 08:34:58 -05:00 committed by GitHub
parent 35a521d762
commit 4fdfd3d15e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -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
);
}

View File

@ -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<Example> {
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 {})])
}
}