mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
Remove select
error if same row/column is provided (#10350)
This PR is in reference to #10215. This PR changes `select` to work even if multiple equal items were provided. This would previously error, but now works ```nushell let arg = [ 1 a ] [[a b c]; [1 2 3] [4 5 6] [7 8 9]] | select $arg ``` # User-Facing Changes Nothing too radical, just experience improvements. Users won't need to pass the values through `unique` beforehand.
This commit is contained in:
parent
7f39609d9a
commit
bbea7da669
@ -214,18 +214,13 @@ fn select(
|
|||||||
Vec::new(),
|
Vec::new(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if unique_rows.contains(val) {
|
|
||||||
return Err(ShellError::GenericError(
|
|
||||||
"Select can't get the same row twice".into(),
|
|
||||||
"duplicated row index".into(),
|
|
||||||
Some(*span),
|
|
||||||
None,
|
|
||||||
Vec::new(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
unique_rows.insert(*val);
|
unique_rows.insert(*val);
|
||||||
}
|
}
|
||||||
_ => new_columns.push(column),
|
_ => {
|
||||||
|
if !new_columns.contains(&column) {
|
||||||
|
new_columns.push(column)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let columns = new_columns;
|
let columns = new_columns;
|
||||||
|
@ -218,10 +218,17 @@ fn select_failed3() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn select_failed4() {
|
fn select_repeated_rows() {
|
||||||
let actual = nu!("[{a: 1 b: 10}, {a:2, b:11}] | select 0 0");
|
let actual = nu!("[[a b c]; [1 2 3] [4 5 6] [7 8 9]] | select 0 0 | to nuon");
|
||||||
|
|
||||||
assert!(actual.err.contains("Select can't get the same row twice"));
|
assert_eq!(actual.out, "[[a, b, c]; [1, 2, 3]]");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn select_repeated_column() {
|
||||||
|
let actual = nu!("[[a b c]; [1 2 3] [4 5 6] [7 8 9]] | select a a | to nuon");
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "[[a]; [1], [4], [7]]");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user