Improve CantFindColumn and ColumnAlreadyExists errors (#7164)

* Improve CantFindColumn and ColumnAlreadyExists errors

* Update tests
This commit is contained in:
Leon
2022-11-20 03:35:55 +10:00
committed by GitHub
parent 41f72b1236
commit 4b83a2d27a
8 changed files with 131 additions and 37 deletions

View File

@ -19,22 +19,15 @@ pub fn get_columns<'a>(input: impl IntoIterator<Item = &'a Value>) -> Vec<String
columns
}
/*
* 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);
}
// If a column doesn't exist in the input, return it.
pub fn nonexistent_column(inputs: Vec<String>, columns: Vec<String>) -> Option<String> {
let set: HashSet<String> = HashSet::from_iter(columns.iter().cloned());
for input in &inputs {
if set.contains(input) {
continue;
}
return true;
return Some(input.clone());
}
false
None
}