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

View File

@ -165,11 +165,11 @@ fn select_ignores_errors_succesfully1() {
let actual = nu!(
cwd: ".", pipeline(
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());
}