mirror of
https://github.com/nushell/nushell.git
synced 2025-04-02 04:07:40 +02:00
Remove record iteration (#4582)
* Remove record iteration * Remove test
This commit is contained in:
parent
917886f8ad
commit
a2c4c92fce
@ -2,8 +2,8 @@ use nu_engine::{eval_block_with_redirect, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
||||
Span, SyntaxShape, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, SyntaxShape,
|
||||
Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -161,64 +161,66 @@ impl Command for Each {
|
||||
}
|
||||
})
|
||||
.into_pipeline_data(ctrlc)),
|
||||
PipelineData::Value(Value::Record { cols, vals, .. }, ..) => {
|
||||
let mut output_cols = vec![];
|
||||
let mut output_vals = vec![];
|
||||
// JT: we'll turn this off for now until we get a better design
|
||||
// leaving it here, but commented-out, for the time being
|
||||
// PipelineData::Value(Value::Record { cols, vals, .. }, ..) => {
|
||||
// let mut output_cols = vec![];
|
||||
// let mut output_vals = vec![];
|
||||
|
||||
for (col, val) in cols.into_iter().zip(vals.into_iter()) {
|
||||
//let block = engine_state.get_block(block_id);
|
||||
// for (col, val) in cols.into_iter().zip(vals.into_iter()) {
|
||||
// //let block = engine_state.get_block(block_id);
|
||||
|
||||
stack.with_env(&orig_env_vars, &orig_env_hidden);
|
||||
// stack.with_env(&orig_env_vars, &orig_env_hidden);
|
||||
|
||||
if let Some(var) = block.signature.get_positional(0) {
|
||||
if let Some(var_id) = &var.var_id {
|
||||
stack.add_var(
|
||||
*var_id,
|
||||
Value::Record {
|
||||
cols: vec!["column".into(), "value".into()],
|
||||
vals: vec![
|
||||
Value::String {
|
||||
val: col.clone(),
|
||||
span: call.head,
|
||||
},
|
||||
val,
|
||||
],
|
||||
span: call.head,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
// if let Some(var) = block.signature.get_positional(0) {
|
||||
// if let Some(var_id) = &var.var_id {
|
||||
// stack.add_var(
|
||||
// *var_id,
|
||||
// Value::Record {
|
||||
// cols: vec!["column".into(), "value".into()],
|
||||
// vals: vec![
|
||||
// Value::String {
|
||||
// val: col.clone(),
|
||||
// span: call.head,
|
||||
// },
|
||||
// val,
|
||||
// ],
|
||||
// span: call.head,
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
match eval_block_with_redirect(
|
||||
&engine_state,
|
||||
&mut stack,
|
||||
&block,
|
||||
PipelineData::new(span),
|
||||
)? {
|
||||
PipelineData::Value(
|
||||
Value::Record {
|
||||
mut cols, mut vals, ..
|
||||
},
|
||||
..,
|
||||
) => {
|
||||
// TODO check that the lengths match when traversing record
|
||||
output_cols.append(&mut cols);
|
||||
output_vals.append(&mut vals);
|
||||
}
|
||||
x => {
|
||||
output_cols.push(col);
|
||||
output_vals.push(x.into_value(span));
|
||||
}
|
||||
}
|
||||
}
|
||||
// match eval_block_with_redirect(
|
||||
// &engine_state,
|
||||
// &mut stack,
|
||||
// &block,
|
||||
// PipelineData::new(span),
|
||||
// )? {
|
||||
// PipelineData::Value(
|
||||
// Value::Record {
|
||||
// mut cols, mut vals, ..
|
||||
// },
|
||||
// ..,
|
||||
// ) => {
|
||||
// // TODO check that the lengths match when traversing record
|
||||
// output_cols.append(&mut cols);
|
||||
// output_vals.append(&mut vals);
|
||||
// }
|
||||
// x => {
|
||||
// output_cols.push(col);
|
||||
// output_vals.push(x.into_value(span));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Ok(Value::Record {
|
||||
cols: output_cols,
|
||||
vals: output_vals,
|
||||
span: call.head,
|
||||
}
|
||||
.into_pipeline_data())
|
||||
}
|
||||
// Ok(Value::Record {
|
||||
// cols: output_cols,
|
||||
// vals: output_vals,
|
||||
// span: call.head,
|
||||
// }
|
||||
// .into_pipeline_data())
|
||||
// }
|
||||
PipelineData::Value(x, ..) => {
|
||||
//let block = engine_state.get_block(block_id);
|
||||
|
||||
|
@ -16,11 +16,6 @@ fn row_iteration() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_iteration() -> TestResult {
|
||||
run_test("([[name, level]; [aa, 100], [bb, 200]] | each { |it| $it | each { |x| if $x.column == \"level\" { $x.value + 100 } else { $x.value } } }).level | get 1", "300")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn row_condition1() -> TestResult {
|
||||
run_test(
|
||||
|
Loading…
Reference in New Issue
Block a user