Lazy dataframes (#5687)

* change between lazy and eager

* when expressions

* examples for aggregations

* more examples for agg

* examples for dataframes

* checked examples

* cargo fmt
This commit is contained in:
Fernando Herrera
2022-05-31 07:29:55 +01:00
committed by GitHub
parent 0769e9b750
commit 997d56a288
50 changed files with 1781 additions and 810 deletions

View File

@ -0,0 +1,70 @@
use super::super::values::NuExpression;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value,
};
#[derive(Clone)]
pub struct ExprAsNu;
impl Command for ExprAsNu {
fn name(&self) -> &str {
"dfr as-nu"
}
fn usage(&self) -> &str {
"Convert expression to a nu value for access and exploration"
}
fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Custom("expression".into()))
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Convert a col expression into a nushell value",
example: "dfr col col_a | dfr as-nu",
result: Some(Value::Record {
cols: vec!["expr".into(), "value".into()],
vals: vec![
Value::String {
val: "column".into(),
span: Span::test_data(),
},
Value::String {
val: "col_a".into(),
span: Span::test_data(),
},
],
span: Span::test_data(),
}),
}]
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let expr = NuExpression::try_from_pipeline(input, call.head)?;
let value = expr.to_value(call.head);
Ok(PipelineData::Value(value, None))
}
}
#[cfg(test)]
mod test {
use super::super::super::test_dataframe::test_dataframe;
use super::super::ExprCol;
use super::*;
#[test]
fn test_examples() {
test_dataframe(vec![Box::new(ExprAsNu {}), Box::new(ExprCol {})])
}
}