mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 23:49:44 +01:00
rename with_sql to query dfr (#6568)
* rename with_sql to query dfr * add search terms * update example command
This commit is contained in:
parent
35a521d762
commit
4fdfd3d15e
@ -13,6 +13,7 @@ mod last;
|
|||||||
mod list;
|
mod list;
|
||||||
mod melt;
|
mod melt;
|
||||||
mod open;
|
mod open;
|
||||||
|
mod query_dfr;
|
||||||
mod rename;
|
mod rename;
|
||||||
mod sample;
|
mod sample;
|
||||||
mod shape;
|
mod shape;
|
||||||
@ -26,7 +27,6 @@ mod to_df;
|
|||||||
mod to_nu;
|
mod to_nu;
|
||||||
mod to_parquet;
|
mod to_parquet;
|
||||||
mod with_column;
|
mod with_column;
|
||||||
mod with_sql;
|
|
||||||
|
|
||||||
use nu_protocol::engine::StateWorkingSet;
|
use nu_protocol::engine::StateWorkingSet;
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ pub use last::LastDF;
|
|||||||
pub use list::ListDF;
|
pub use list::ListDF;
|
||||||
pub use melt::MeltDF;
|
pub use melt::MeltDF;
|
||||||
pub use open::OpenDataFrame;
|
pub use open::OpenDataFrame;
|
||||||
|
pub use query_dfr::QueryDfr;
|
||||||
pub use rename::RenameDF;
|
pub use rename::RenameDF;
|
||||||
pub use sample::SampleDF;
|
pub use sample::SampleDF;
|
||||||
pub use shape::ShapeDF;
|
pub use shape::ShapeDF;
|
||||||
@ -58,7 +59,6 @@ pub use to_df::ToDataFrame;
|
|||||||
pub use to_nu::ToNu;
|
pub use to_nu::ToNu;
|
||||||
pub use to_parquet::ToParquet;
|
pub use to_parquet::ToParquet;
|
||||||
pub use with_column::WithColumn;
|
pub use with_column::WithColumn;
|
||||||
pub use with_sql::WithSql;
|
|
||||||
|
|
||||||
pub fn add_eager_decls(working_set: &mut StateWorkingSet) {
|
pub fn add_eager_decls(working_set: &mut StateWorkingSet) {
|
||||||
macro_rules! bind_command {
|
macro_rules! bind_command {
|
||||||
@ -87,6 +87,7 @@ pub fn add_eager_decls(working_set: &mut StateWorkingSet) {
|
|||||||
ListDF,
|
ListDF,
|
||||||
MeltDF,
|
MeltDF,
|
||||||
OpenDataFrame,
|
OpenDataFrame,
|
||||||
|
QueryDfr,
|
||||||
RenameDF,
|
RenameDF,
|
||||||
SampleDF,
|
SampleDF,
|
||||||
ShapeDF,
|
ShapeDF,
|
||||||
@ -97,7 +98,6 @@ pub fn add_eager_decls(working_set: &mut StateWorkingSet) {
|
|||||||
ToDataFrame,
|
ToDataFrame,
|
||||||
ToNu,
|
ToNu,
|
||||||
ToParquet,
|
ToParquet,
|
||||||
WithColumn,
|
WithColumn
|
||||||
WithSql
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,15 @@ use nu_protocol::{
|
|||||||
// https://github.com/pola-rs/polars/tree/master/polars-sql
|
// https://github.com/pola-rs/polars/tree/master/polars-sql
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct WithSql;
|
pub struct QueryDfr;
|
||||||
|
|
||||||
impl Command for WithSql {
|
impl Command for QueryDfr {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"with-sql"
|
"query dfr"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
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 {
|
fn signature(&self) -> Signature {
|
||||||
@ -33,10 +33,14 @@ impl Command for WithSql {
|
|||||||
.category(Category::Custom("dataframe".into()))
|
.category(Category::Custom("dataframe".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
|
vec!["dataframe", "sql", "search"]
|
||||||
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Query dataframe using SQL",
|
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(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"a".to_string(),
|
"a".to_string(),
|
||||||
@ -97,6 +101,6 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_examples() {
|
fn test_examples() {
|
||||||
test_dataframe(vec![Box::new(WithSql {})])
|
test_dataframe(vec![Box::new(QueryDfr {})])
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user