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::ast::Call;
|
||||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, SyntaxShape,
|
||||||
Span, SyntaxShape, Value,
|
Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -161,64 +161,66 @@ impl Command for Each {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.into_pipeline_data(ctrlc)),
|
.into_pipeline_data(ctrlc)),
|
||||||
PipelineData::Value(Value::Record { cols, vals, .. }, ..) => {
|
// JT: we'll turn this off for now until we get a better design
|
||||||
let mut output_cols = vec![];
|
// leaving it here, but commented-out, for the time being
|
||||||
let mut output_vals = vec![];
|
// 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()) {
|
// for (col, val) in cols.into_iter().zip(vals.into_iter()) {
|
||||||
//let block = engine_state.get_block(block_id);
|
// //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) = block.signature.get_positional(0) {
|
||||||
if let Some(var_id) = &var.var_id {
|
// if let Some(var_id) = &var.var_id {
|
||||||
stack.add_var(
|
// stack.add_var(
|
||||||
*var_id,
|
// *var_id,
|
||||||
Value::Record {
|
// Value::Record {
|
||||||
cols: vec!["column".into(), "value".into()],
|
// cols: vec!["column".into(), "value".into()],
|
||||||
vals: vec![
|
// vals: vec![
|
||||||
Value::String {
|
// Value::String {
|
||||||
val: col.clone(),
|
// val: col.clone(),
|
||||||
span: call.head,
|
// span: call.head,
|
||||||
},
|
// },
|
||||||
val,
|
// val,
|
||||||
],
|
// ],
|
||||||
span: call.head,
|
// span: call.head,
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
match eval_block_with_redirect(
|
// match eval_block_with_redirect(
|
||||||
&engine_state,
|
// &engine_state,
|
||||||
&mut stack,
|
// &mut stack,
|
||||||
&block,
|
// &block,
|
||||||
PipelineData::new(span),
|
// PipelineData::new(span),
|
||||||
)? {
|
// )? {
|
||||||
PipelineData::Value(
|
// PipelineData::Value(
|
||||||
Value::Record {
|
// Value::Record {
|
||||||
mut cols, mut vals, ..
|
// mut cols, mut vals, ..
|
||||||
},
|
// },
|
||||||
..,
|
// ..,
|
||||||
) => {
|
// ) => {
|
||||||
// TODO check that the lengths match when traversing record
|
// // TODO check that the lengths match when traversing record
|
||||||
output_cols.append(&mut cols);
|
// output_cols.append(&mut cols);
|
||||||
output_vals.append(&mut vals);
|
// output_vals.append(&mut vals);
|
||||||
}
|
// }
|
||||||
x => {
|
// x => {
|
||||||
output_cols.push(col);
|
// output_cols.push(col);
|
||||||
output_vals.push(x.into_value(span));
|
// output_vals.push(x.into_value(span));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
Ok(Value::Record {
|
// Ok(Value::Record {
|
||||||
cols: output_cols,
|
// cols: output_cols,
|
||||||
vals: output_vals,
|
// vals: output_vals,
|
||||||
span: call.head,
|
// span: call.head,
|
||||||
}
|
// }
|
||||||
.into_pipeline_data())
|
// .into_pipeline_data())
|
||||||
}
|
// }
|
||||||
PipelineData::Value(x, ..) => {
|
PipelineData::Value(x, ..) => {
|
||||||
//let block = engine_state.get_block(block_id);
|
//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]
|
#[test]
|
||||||
fn row_condition1() -> TestResult {
|
fn row_condition1() -> TestResult {
|
||||||
run_test(
|
run_test(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user