Support records in reject command (#4373)

* support records in reject command

* add reject command tests
This commit is contained in:
panicbit
2022-02-08 21:57:46 +01:00
committed by GitHub
parent 6d303f2ca3
commit cf20eed7bc
3 changed files with 99 additions and 0 deletions

View File

@ -82,6 +82,20 @@ fn reject(
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()))
}
PipelineData::Value(
Value::Record {
mut cols,
mut vals,
span,
},
metadata,
) => {
reject_record_columns(&mut cols, &mut vals, &columns);
let record = Value::Record { cols, vals, span };
Ok(PipelineData::Value(record, metadata))
}
PipelineData::ListStream(stream, ..) => {
let mut output = vec![];
@ -155,3 +169,12 @@ fn get_keep_columns(mut input: Vec<String>, rejects: Vec<String>) -> Vec<String>
}
input
}
fn reject_record_columns(cols: &mut Vec<String>, vals: &mut Vec<Value>, rejects: &[String]) {
for reject in rejects {
if let Some(index) = cols.iter().position(|value| value == reject) {
cols.swap_remove(index);
vals.swap_remove(index);
}
}
}