mirror of
https://github.com/nushell/nushell.git
synced 2025-07-09 10:57:54 +02:00
* lazyframe definition * expressions and lazy frames * new alias expression * more expression commands * updated to polars main * more expressions and groupby * more expressions, fetch and sort-by * csv reader * removed open csv * unique function * joining functions * join lazy frames commands with eager commands * corrected tests * Update .gitignore * Update .gitignore Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
58 lines
1.4 KiB
Rust
58 lines
1.4 KiB
Rust
use super::super::values::NuExpression;
|
|
|
|
use nu_engine::CallExt;
|
|
use nu_protocol::{
|
|
ast::Call,
|
|
engine::{Command, EngineState, Stack},
|
|
Category, Example, PipelineData, ShellError, Signature, SyntaxShape,
|
|
};
|
|
|
|
#[derive(Clone)]
|
|
pub struct ExprAlias;
|
|
|
|
impl Command for ExprAlias {
|
|
fn name(&self) -> &str {
|
|
"dfr as"
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Creates an alias expression"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build(self.name())
|
|
.required(
|
|
"Alias name",
|
|
SyntaxShape::String,
|
|
"Alias name for the expression",
|
|
)
|
|
.category(Category::Custom("expressions".into()))
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "Creates and alias expression",
|
|
example: "(dfr col a | df as new_a)",
|
|
result: None,
|
|
}]
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
engine_state: &EngineState,
|
|
stack: &mut Stack,
|
|
call: &Call,
|
|
input: PipelineData,
|
|
) -> Result<PipelineData, ShellError> {
|
|
let alias: String = call.req(engine_state, stack, 0)?;
|
|
|
|
let expr = NuExpression::try_from_pipeline(input, call.head)?;
|
|
let expr: NuExpression = expr.into_polars().alias(alias.as_str()).into();
|
|
|
|
Ok(PipelineData::Value(
|
|
NuExpression::into_value(expr, call.head),
|
|
None,
|
|
))
|
|
}
|
|
}
|