#1434 unconfirmed
pathsny (at gmail)

slice seems broken on datamapper collections

Reported by pathsny (at gmail) | October 14th, 2010 @ 09:11 AM

[1,2,3][1..-1] = [2,3] Foo.all[1..-1]

ArgumentError: +options[:limit]+ must be greater than or equal to 0, but was -1

from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/query.rb:922:in `assert_valid_limit'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/query.rb:773:in `assert_valid_options'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/query.rb:767:in `each'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/query.rb:767:in `assert_valid_options'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/query.rb:363:in `update'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/query.rb:596:in `slice!'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/query.rb:568:in `slice'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/collection.rb:1413:in `sliced_query'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.0.2/lib/dm-core/collection.rb:400:in `[]'
from (irb):2

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 24th, 2010 @ 10:08 PM

    • State changed from “new” to “unconfirmed”

    I think we can fix this, but I want to get clear on what sort of query should be executed under the hood. To constraint the problem set a bit, we should talk about SQL, and how a query like Foo.all[1..-1] should be satisfied.

    Given an Array, [1..-1] would cause every entry to be returned except the very first entry. For some DBs, in SQL, when you specify an offset you also need to specify a limit (a maximum number of rows to return).

    I've seen this handled in the past by specifying ridiculously large limits, like 2**64-1, which allows you to specify an offset and an effectively unlimited number of rows. This allows you to specify whatever offset you like, and have it work like it does with an Array. (well, except in the very rare case where you have more than 2**64-1 rows returned, but you probably have bigger problems if your query does return that many results and you plan to load them into memory ;)

    Alternatively we could execute a COUNT query just before to find out how many rows there are, and then use that in place of -1.

    Another approach would be to fetch all the rows, but tell the Collection to throw-away all rows before the offset.

    I'm leaning towards the first approach, since I'm pretty sure it will work with more than just RDBMS, but it also doesn't feel as wasteful as the other approaches.

    What does everyone else think?

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages