# Description The second `Value` is redundant and will consume five extra bytes on each transmission of a custom value to/from a plugin. # User-Facing Changes This is a breaking change to the plugin protocol. The [example in the protocol reference](https://www.nushell.sh/contributor-book/plugin_protocol_reference.html#value) becomes ```json { "Custom": { "val": { "type": "PluginCustomValue", "name": "database", "data": [36, 190, 127, 40, 12, 3, 46, 83], "notify_on_drop": true }, "span": { "start": 320, "end": 340 } } } ``` instead of ```json { "CustomValue": { ... } } ``` # After Submitting Update plugin protocol reference
74 lines
2.0 KiB
Rust
74 lines
2.0 KiB
Rust
use crate::dataframe::values::{Column, NuDataFrame, NuLazyFrame};
|
|
use nu_engine::command_prelude::*;
|
|
|
|
#[derive(Clone)]
|
|
pub struct LazyCollect;
|
|
|
|
impl Command for LazyCollect {
|
|
fn name(&self) -> &str {
|
|
"dfr collect"
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Collect lazy dataframe into eager dataframe."
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build(self.name())
|
|
.input_output_type(
|
|
Type::Custom("dataframe".into()),
|
|
Type::Custom("dataframe".into()),
|
|
)
|
|
.category(Category::Custom("lazyframe".into()))
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "drop duplicates",
|
|
example: "[[a b]; [1 2] [3 4]] | dfr into-lazy | dfr collect",
|
|
result: Some(
|
|
NuDataFrame::try_from_columns(
|
|
vec![
|
|
Column::new(
|
|
"a".to_string(),
|
|
vec![Value::test_int(1), Value::test_int(3)],
|
|
),
|
|
Column::new(
|
|
"b".to_string(),
|
|
vec![Value::test_int(2), Value::test_int(4)],
|
|
),
|
|
],
|
|
None,
|
|
)
|
|
.expect("simple df for test should not fail")
|
|
.into_value(Span::test_data()),
|
|
),
|
|
}]
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
_engine_state: &EngineState,
|
|
_stack: &mut Stack,
|
|
call: &Call,
|
|
input: PipelineData,
|
|
) -> Result<PipelineData, ShellError> {
|
|
let lazy = NuLazyFrame::try_from_pipeline(input, call.head)?;
|
|
let eager = lazy.collect(call.head)?;
|
|
let value = Value::custom(Box::new(eager), call.head);
|
|
|
|
Ok(PipelineData::Value(value, None))
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::super::super::test_dataframe::test_dataframe;
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_examples() {
|
|
test_dataframe(vec![Box::new(LazyCollect {})])
|
|
}
|
|
}
|