fix: empty cell in select (#7639)

This commit is contained in:
Access 2022-12-31 19:19:10 +08:00 committed by GitHub
parent 7aa2a57434
commit 9382dd6d55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 11 deletions

View File

@ -149,7 +149,7 @@ fn select(
) => { ) => {
let mut output = vec![]; let mut output = vec![];
let mut columns_with_value = Vec::new(); let mut columns_with_value = Vec::new();
let mut allempty = true;
for input_val in input_vals { for input_val in input_vals {
if !columns.is_empty() { if !columns.is_empty() {
let mut cols = vec![]; let mut cols = vec![];
@ -158,6 +158,7 @@ fn select(
//FIXME: improve implementation to not clone //FIXME: improve implementation to not clone
match input_val.clone().follow_cell_path(&path.members, false) { match input_val.clone().follow_cell_path(&path.members, false) {
Ok(fetcher) => { Ok(fetcher) => {
allempty = false;
cols.push(path.into_string().replace('.', "_")); cols.push(path.into_string().replace('.', "_"));
vals.push(fetcher); vals.push(fetcher);
if !columns_with_value.contains(&path) { if !columns_with_value.contains(&path) {
@ -166,9 +167,11 @@ fn select(
} }
Err(e) => { Err(e) => {
if ignore_errors { if ignore_errors {
return Ok(Value::nothing(call_span).into_pipeline_data()); cols.push(path.into_string().replace('.', "_"));
vals.push(Value::Nothing { span })
} else {
return Err(e);
} }
return Err(e);
} }
} }
} }
@ -178,11 +181,14 @@ fn select(
output.push(input_val) output.push(input_val)
} }
} }
if allempty {
Ok(output Ok(Value::nothing(call_span).into_pipeline_data())
.into_iter() } else {
.into_pipeline_data(engine_state.ctrlc.clone()) Ok(output
.set_metadata(metadata)) .into_iter()
.into_pipeline_data(engine_state.ctrlc.clone())
.set_metadata(metadata))
}
} }
PipelineData::ListStream(stream, metadata, ..) => { PipelineData::ListStream(stream, metadata, ..) => {
let mut values = vec![]; let mut values = vec![];

View File

@ -165,11 +165,11 @@ fn select_ignores_errors_succesfully1() {
let actual = nu!( let actual = nu!(
cwd: ".", pipeline( cwd: ".", pipeline(
r#" r#"
[{a: 1, b: 2} {a: 3, b: 5} {a: 3}] | select -i b [{a: 1, b: 2} {a: 3, b: 5} {a: 3}] | select -i b | length
"# "#
)); ));
assert!(actual.out.is_empty()); assert_eq!(actual.out, "3".to_string());
assert!(actual.err.is_empty()); assert!(actual.err.is_empty());
} }