2022-01-01 02:39:58 +01:00
|
|
|
use nu_protocol::Value;
|
2022-01-24 05:52:19 +01:00
|
|
|
use std::collections::HashSet;
|
2022-01-01 02:39:58 +01:00
|
|
|
|
|
|
|
pub fn get_columns(input: &[Value]) -> Vec<String> {
|
|
|
|
let mut columns = vec![];
|
|
|
|
|
|
|
|
for item in input {
|
|
|
|
if let Value::Record { cols, vals: _, .. } = item {
|
|
|
|
for col in cols {
|
|
|
|
if !columns.contains(col) {
|
|
|
|
columns.push(col.to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
columns
|
|
|
|
}
|
2022-01-24 05:52:19 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if any of the columns inside the input
|
|
|
|
* does not exist in a vec of columns
|
|
|
|
*/
|
|
|
|
|
|
|
|
pub fn column_does_not_exist(inputs: Vec<String>, columns: Vec<String>) -> bool {
|
|
|
|
let mut set = HashSet::new();
|
|
|
|
for column in columns {
|
|
|
|
set.insert(column);
|
|
|
|
}
|
|
|
|
|
|
|
|
for input in &inputs {
|
|
|
|
if set.contains(input) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|