nushell/crates/nu-engine/src/column.rs
Maxim Zhiburt 8d8b011702
Bump tabled dependency to 0.11 (#8922)
close? #8060

Quite a bit of refactoring took place.
I believe a few improvements to collapse/expand were made.

I've tried to track any performance regressions and seems like it is
fine.

I've noticed something different now with default configuration path or
something in this regard?
So I might missed something while testing because of this.

Requires some oversight.

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-04-26 13:56:10 -05:00

33 lines
779 B
Rust

use nu_protocol::Value;
use std::collections::HashSet;
pub fn get_columns(input: &[Value]) -> Vec<String> {
let mut columns = vec![];
for item in input {
let Value::Record { cols, .. } = item else {
return vec![];
};
for col in cols {
if !columns.contains(col) {
columns.push(col.to_string());
}
}
}
columns
}
// 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 Some(input.clone());
}
None
}