Show entire table if number of rows requested for last is greater than table size (#2112)

* Show entire table if number of rows requested for last is greater than table size

* rustfmt

* Add test
This commit is contained in:
Joseph T. Lyons 2020-07-04 21:04:17 -04:00 committed by GitHub
parent 8ea2307815
commit 9e82e5a2fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -69,16 +69,18 @@ async fn last(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStr
1
};
let mut values_vec_deque = VecDeque::new();
let count = rows_desired as usize;
if count < v.len() {
let k = v.len() - count;
let k = if count < v.len() {
v.len() - count
} else {
return Ok(futures::stream::iter(v).to_output_stream());
};
for x in v[k..].iter() {
values_vec_deque.push_back(ReturnSuccess::value(x.clone()));
}
let mut values_vec_deque = VecDeque::new();
for x in v[k..].iter() {
values_vec_deque.push_back(ReturnSuccess::value(x.clone()));
}
Ok(futures::stream::iter(values_vec_deque).to_output_stream())

View File

@ -54,3 +54,15 @@ fn gets_last_row_when_no_amount_given() {
assert_eq!(actual.out, "1");
})
}
#[test]
fn requests_more_rows_than_table_has() {
let actual = nu!(
cwd: ".", pipeline(
r#"
date | last 50 | count
"#
));
assert_eq!(actual.out, "1");
}