mirror of
https://github.com/nushell/nushell.git
synced 2025-03-29 09:06:52 +01:00
User error propagation operator (#2201)
This commit is contained in:
parent
b358804904
commit
dbe0effd67
@ -98,14 +98,11 @@ pub async fn group_by_date(
|
|||||||
Grouper::ByDate(None)
|
Grouper::ByDate(None)
|
||||||
};
|
};
|
||||||
|
|
||||||
match (grouper_date, grouper_column) {
|
let value_result = match (grouper_date, grouper_column) {
|
||||||
(Grouper::ByDate(None), GroupByColumn::Name(None)) => {
|
(Grouper::ByDate(None), GroupByColumn::Name(None)) => {
|
||||||
let block = Box::new(move |_, row: &Value| row.format("%Y-%b-%d"));
|
let block = Box::new(move |_, row: &Value| row.format("%Y-%b-%d"));
|
||||||
|
|
||||||
match crate::utils::data::group(&values, &Some(block), &name) {
|
crate::utils::data::group(&values, &Some(block), &name)
|
||||||
Ok(grouped) => Ok(OutputStream::one(ReturnSuccess::value(grouped))),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
(Grouper::ByDate(None), GroupByColumn::Name(Some(column_name))) => {
|
(Grouper::ByDate(None), GroupByColumn::Name(Some(column_name))) => {
|
||||||
let block = Box::new(move |_, row: &Value| {
|
let block = Box::new(move |_, row: &Value| {
|
||||||
@ -117,18 +114,12 @@ pub async fn group_by_date(
|
|||||||
group_key?.format("%Y-%b-%d")
|
group_key?.format("%Y-%b-%d")
|
||||||
});
|
});
|
||||||
|
|
||||||
match crate::utils::data::group(&values, &Some(block), &name) {
|
crate::utils::data::group(&values, &Some(block), &name)
|
||||||
Ok(grouped) => Ok(OutputStream::one(ReturnSuccess::value(grouped))),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
(Grouper::ByDate(Some(fmt)), GroupByColumn::Name(None)) => {
|
(Grouper::ByDate(Some(fmt)), GroupByColumn::Name(None)) => {
|
||||||
let block = Box::new(move |_, row: &Value| row.format(&fmt));
|
let block = Box::new(move |_, row: &Value| row.format(&fmt));
|
||||||
|
|
||||||
match crate::utils::data::group(&values, &Some(block), &name) {
|
crate::utils::data::group(&values, &Some(block), &name)
|
||||||
Ok(grouped) => Ok(OutputStream::one(ReturnSuccess::value(grouped))),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
(Grouper::ByDate(Some(fmt)), GroupByColumn::Name(Some(column_name))) => {
|
(Grouper::ByDate(Some(fmt)), GroupByColumn::Name(Some(column_name))) => {
|
||||||
let block = Box::new(move |_, row: &Value| {
|
let block = Box::new(move |_, row: &Value| {
|
||||||
@ -140,12 +131,11 @@ pub async fn group_by_date(
|
|||||||
group_key?.format(&fmt)
|
group_key?.format(&fmt)
|
||||||
});
|
});
|
||||||
|
|
||||||
match crate::utils::data::group(&values, &Some(block), &name) {
|
crate::utils::data::group(&values, &Some(block), &name)
|
||||||
Ok(grouped) => Ok(OutputStream::one(ReturnSuccess::value(grouped))),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(OutputStream::one(ReturnSuccess::value(value_result?)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,10 +56,9 @@ async fn insert(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputS
|
|||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Row(_),
|
value: UntaggedValue::Row(_),
|
||||||
..
|
..
|
||||||
} => match row.insert_data_at_column_path(&column, value.clone()) {
|
} => Ok(ReturnSuccess::Value(
|
||||||
Ok(v) => Ok(ReturnSuccess::Value(v)),
|
row.insert_data_at_column_path(&column, value.clone())?,
|
||||||
Err(err) => Err(err),
|
)),
|
||||||
},
|
|
||||||
|
|
||||||
Value { tag, .. } => Err(ShellError::labeled_error(
|
Value { tag, .. } => Err(ShellError::labeled_error(
|
||||||
"Unrecognized type in stream",
|
"Unrecognized type in stream",
|
||||||
|
@ -50,12 +50,7 @@ pub fn calculate(values: &[Value], name: &Tag, mf: MathFunction) -> Result<Value
|
|||||||
// The mathematical function operates over the columns of the table
|
// The mathematical function operates over the columns of the table
|
||||||
let mut column_totals = IndexMap::new();
|
let mut column_totals = IndexMap::new();
|
||||||
for (col_name, col_vals) in column_values {
|
for (col_name, col_vals) in column_values {
|
||||||
match mf(&col_vals, &name) {
|
column_totals.insert(col_name, mf(&col_vals, &name)?);
|
||||||
Ok(result) => {
|
|
||||||
column_totals.insert(col_name, result);
|
|
||||||
}
|
|
||||||
Err(err) => return Err(err),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(UntaggedValue::Row(Dictionary {
|
Ok(UntaggedValue::Row(Dictionary {
|
||||||
|
Loading…
Reference in New Issue
Block a user