Repository navigation
Allow passing a range to take - #471
Conversation
| /// Aggregate several ordered ranges into one, computing the intersection. | ||
| /// | ||
| /// Returns a tuple of `(start, end)`, where `end` is optional. | ||
| fn range_of_ranges(ranges: Vec<Range>) -> Result<(i64, Option<i64>)> { |
There was a problem hiding this comment.
This seems like a very complicated implementation for what it's actually doing, but I'm not sure of an easier one...
There was a problem hiding this comment.
Algorithmically, this is as concise as you can get (I think). But code-wise, this could be compressed, by:
- first mapping all ranges to Rust's
Range<i64>, - replacing
cs > lengthwith a check for negative length at the end, - replace a the two
if let Somewithunwrap_orandmap
| Some( | ||
| 10, | ||
| ), | ||
| ) |
There was a problem hiding this comment.
Seems very verbose from rustfmt...
There was a problem hiding this comment.
would assert_yaml_snapshot work? I believe tuple and Option have Serializable trait...
|
Sorry, couldn't help it: I did a refactor of But I found a mistake, best seen in: take 101..110- LIMIT 110 OFFSET 100
+ LIMIT 10 OFFSET 100Limit directly tells how much rows should there be in the result - its applied after offset. |
| Some( | ||
| 10, | ||
| ), | ||
| ) |
There was a problem hiding this comment.
would assert_yaml_snapshot work? I believe tuple and Option have Serializable trait...
| /// Aggregate several ordered ranges into one, computing the intersection. | ||
| /// | ||
| /// Returns a tuple of `(start, end)`, where `end` is optional. | ||
| fn range_of_ranges(ranges: Vec<Range>) -> Result<(i64, Option<i64>)> { |
There was a problem hiding this comment.
Algorithmically, this is as concise as you can get (I think). But code-wise, this could be compressed, by:
- first mapping all ranges to Rust's
Range<i64>, - replacing
cs > lengthwith a check for negative length at the end, - replace a the two
if let Somewithunwrap_orandmap
|
Ahh. I've written these comments before and they are posted only after I finish the review... oops |
| } | ||
|
|
||
| impl<T> OrMap<T> for Option<T> { | ||
| fn or_map<F>(self, b: Self, f: F) -> Self |
| // There can be many takes, but they have to be consecutive | ||
| // For example `take 100 | sort a | take 10` can't be one CTE. | ||
| // But this is enforced by transform order anyway. | ||
| "Take" => false, |
There was a problem hiding this comment.
Thanks for adding this!
| date | ||
| LIMIT | ||
| 110 OFFSET 100 | ||
| 10 OFFSET 100 |
There was a problem hiding this comment.
I guess this was wrong in my code...
Ha, yeah I do this a lot... |


This is a WIP. Ideally we can do
And it'll translate to a
LIMIT&OFFSETPassing
take 10would be the same as passingtake 1..10.