Skip to content

Error in case the user forgets to coerce to array #969

Closed

Description

@neumino

Query:

r.expr({value:r.db('cakemeter').table('stars').filter({'repo': 'rethinkdb'}).map(r.row('id'))})

Error:

RqlRuntimeError: Expected type DATUM but found SEQUENCE:
OPAQUE VALUE SEQUENCE in:
{value: r.db("cakemeter").table("stars").filter({repo: "rethinkdb"}).map(function(var_0) { return r.row("id"); })}
^^

Questions:

  • Is the backtrace broken? (javascript driver)
  • Is opaque sequence a term we want to keep?
    • If yes we should document it
    • If no, we should replace it.
  • Can we make the message a little more friendly like with an extra "Did you forget to coerce to an array?"

Tagging in backlog.

Activity

  1. coffeemug commented on Jun 10, 2013

    @coffeemug
    Contributor

    @neumino -- could you check what the backtrace looks like in Python and Ruby?

  2. neumino commented on Jun 10, 2013

    @neumino
    MemberAuthor

    For python

    >>> r.expr({"value":r.db('cakemeter').table('stars').filter({'repo': 'rethinkdb'}).map(r.row['id'])}).run()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/site-packages/rethinkdb/ast.py", line 47, in run
        return c._start(self, **global_opt_args)
      File "/usr/lib/python2.7/site-packages/rethinkdb/net.py", line 113, in _start
        return self._send_query(query, term, noreply)
      File "/usr/lib/python2.7/site-packages/rethinkdb/net.py", line 179, in _send_query
        raise RqlRuntimeError(message, term, frames)
    rethinkdb.errors.RqlRuntimeError: Expected type DATUM but found SEQUENCE:
    OPAQUE VALUE SEQUENCE in:
    {'value': r.db('cakemeter').table('stars').filter({'repo': 'rethinkdb'}).map(lambda var_4: r.row['id'])}
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

    Ruby

    irb(main):014:0> r.expr({"value" => r.db("cakemeter").table("stars").filter("repo" => "rethinkdb") }).map{ |doc| doc["id"]}.run()
    RethinkDB::RqlRuntimeError: Expected type DATUM but found SELECTION:
    OPAQUE VALUE SELECTION
    Backtrace:
    r({:value =>
       r.db("cakemeter").table("stars").filter(
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         {:repo => "rethinkdb"}
         ^^^^^^^^^^^^^^^^^^^^^^
       )}).map {|var_1|
       ^
      var_1["id"]
    }
    Erroneous_Portion_Constructed:
        from (irb):14:in `irb_binding'
        from /usr/lib/ruby/2.0.0/irb/workspace.rb:86:in `eval'
        from /usr/lib/ruby/2.0.0/irb/workspace.rb:86:in `evaluate'
        from /usr/lib/ruby/2.0.0/irb/context.rb:380:in `evaluate'
        from /usr/lib/ruby/2.0.0/irb.rb:492:in `block (2 levels) in eval_input'
        from /usr/lib/ruby/2.0.0/irb.rb:624:in `signal_status'
        from /usr/lib/ruby/2.0.0/irb.rb:489:in `block in eval_input'
        from /usr/lib/ruby/2.0.0/irb/ruby-lex.rb:247:in `block (2 levels) in each_top_level_statement'
        from /usr/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in `loop'
        from /usr/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
        from /usr/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in `catch'
        from /usr/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in `each_top_level_statement'
        from /usr/lib/ruby/2.0.0/irb.rb:488:in `eval_input'
        from /usr/lib/ruby/2.0.0/irb.rb:397:in `block in start'
        from /usr/lib/ruby/2.0.0/irb.rb:396:in `catch'
        from /usr/lib/ruby/2.0.0/irb.rb:396:in `start'
        from /usr/bin/irb:12:in `<main>'
    Called:
        from /home/michel/.gem/ruby/2.0.0/gems/rethinkdb-1.5.0.0/lib/shim.rb:44:in `rescue in response_to_native'
        from /home/michel/.gem/ruby/2.0.0/gems/rethinkdb-1.5.0.0/lib/shim.rb:27:in `response_to_native'
        from /home/michel/.gem/ruby/2.0.0/gems/rethinkdb-1.5.0.0/lib/net.rb:129:in `run'
        from /home/michel/.gem/ruby/2.0.0/gems/rethinkdb-1.5.0.0/lib/net.rb:26:in `run'
        from (irb):14
        from /usr/bin/irb:12:in `<main>'
  3. neumino commented on Jun 10, 2013

    @neumino
    MemberAuthor

    The first error was caught with the data explorer.
    Using the last JavaScript driver yield the same backtrace.

  4. mlucy commented on Jun 10, 2013

    @mlucy
    Member

    I think this should be broken out into two issues: a "fix the backtrace" issue assigned to @wmrowan and a "fix the error message" issue assigned to me.

  5. jdoliner commented on Jun 10, 2013

    @jdoliner
    Contributor

    There's also some question of if we want to recommend to people that they coerce to array here. Looking at the query @neumino wrote there if he were to follow that advice it's likely he's going to just wind up running afoul of the OOM killer and what he really wants to do is restructure the query to return a stream. That's hard to recommend though.

    Also do we have a static limit on the size of arrays? That would at least make it unlikely for such a query to crash the server.

  6. mlucy commented on Jun 10, 2013

    @mlucy
    Member

    We did at one point, but it was an absurdly high limit and I can't seem to find it in the code any more.

  7. jdoliner commented on Jun 10, 2013

    @jdoliner
    Contributor

    There's also of course the other solution to this problem which is that we could make it so this isn't an error. I actually think that might be worth considering in the future since stuff like this has come up a few times.

  8. mlucy commented on Jun 10, 2013

    @mlucy
    Member

    I wouldn't want to do that without adding a limit to array sizes. I wouldn't want to do it then, either, because I'm worried that people will write and test queries on a small dataset, then deploy to production, and their queries will mysteriously start failing once their table gets big enough to trip the array size limit.

  9. neumino commented on Jun 10, 2013

    @neumino
    MemberAuthor

    I don't think a lot of people will have to use coerce (which is why I tagged in backlog).

    I think the current behavior is fine as long as the error is a little more user friendly (it's the first time I see the term "opaque sequence".

    @coffeemug wanted to have a error/troubleshooting page on the website, so we could provide a link to people to explaining why they need to coerce and the risks. That would be a good case.

  10. jdoliner commented on Jun 10, 2013

    @jdoliner
    Contributor

    @mlucy you misunderstand. I'm saying you never have to deal with arrays at all. If you run:
    {"foo" : r.table("foo"), "bar" : r.table("bar"}
    You get back a dict with cursor objects as the values (and strings as the keys). It would require moving the protobuf file around a bit. But I actually don't see any reason it's not doable and I think it might save people having to hit snags in the type system.

    Also this has some interesting effects on other issues for example if you could return more than one stream from the same query then r.table("foo").group(...) could actually return some very meaningful and useful results. (Although there are some other issues with this.)

  11. neumino commented on Jun 10, 2013

    @neumino
    MemberAuthor

    I'm strongly opposed of passing cursors inside an objects as a result because that would make the JavaScript driver unusable.

    At least if it's the default behavior.

  12. mlucy commented on Jun 10, 2013

    @mlucy
    Member

    @jdoliner -- allowing sequences to exist inside of data introduces a whole host of problems. Off the top of my head:

    • How do you return them to the user? All at once, or do you have some sort of composite cursor? (As @neumino points out, in languages that can't block the latter solution is really clunky.)
    • What do you do to forbid people from accessing the data multiple times in RQL? What if the enclosing object is stored in a variable?
    • What do you do if people try to compare two such objects? Do you consume the stream so it can't be accessed again? Or do you force the whole thing into memory?
  13. jdoliner commented on Jun 10, 2013

    @jdoliner
    Contributor

    How do you return them to the user?

    I was imagining that {"foo" : r.table("foo"), "bar" : r.table("bar"} would return the same thing as:
    {"foo" : r.table("foo").run(), "bar" : r.table("bar").run()}. I'm unclear on why you'd need a composite cursor here.

    What if the enclosing object is stored in a variable?

    We could just disallow storing data which contains streams in it in variables. It might be a bit of a pain to traverse the object looking for streams but it doesn't seem impossible to me.

    What do you do if people try to compare two such objects?

    Similarly we'd have to disallow comparing objects that contain streams. Basically everything you can't do with a stream you now can't do with objects containing streams.

  14. jdoliner commented on Jun 10, 2013

    @jdoliner
    Contributor

    Also just to clarify I'm not suggesting a timeline here but I do think it might let us do some interesting things so I think it's worth thinking about a bit.

  15. jdoliner commented on Jun 10, 2013

    @jdoliner
    Contributor

    @neumino This would lead to a change to the javascript driver but I think it could be made usable.

  16. mlucy commented on Jun 10, 2013

    @mlucy
    Member

    @jdoliner -- {"foo" : r.table("foo").run(), "bar" : r.table("bar").run()} is what I meant by a composite cursor, because it contains multiple cursors. This isn't completely unreasonable in Python/Ruby, but in JS which can't block it would be difficult to have a reasonable interface. What would the callback take, in your mind?

  17. mlucy commented on Jun 10, 2013

    @mlucy
    Member

    I opened separate issues for the error message, the array size limit, and the backtrace problem, since this issue seems to have morphed into a discussion of whether streams should be allowed in data.

  18. jdoliner commented on Jun 10, 2013

    @jdoliner
    Contributor

    @mlucy In my mind in javascript the callback would be called once with the object so in the example we have going your callback would be called with the object {"foo" : CursorObject, "bar" : CursorObject}. Then each of those cursor objects would have an iterate method so you could say things like:

    object["foo"].iterate(function (doc) { alert(doc['value']); }

    The only question is what happens now when the result of the query is a single stream. We could do what we're doing now and just say that if a query returns a single stream we automatically use the callback to iterate it. In one sense this is nice because it saves you some typing on the other hand this is something that separates the Javascript drivers from the other drivers and it makes something that's fairly reasonable in the other 2 a bit weird in javascript.

    My sense is that it'll be painful for people to have to change how they handle streams at this point so we shouldn't change it but I also think that having this little wart in Javascript might be okay since being able to return multiple cursors is actually pretty nice.

  19. srh commented on May 17, 2017

    @srh
    Contributor

    Closing since all that's left is miscellaneous discussion about whether streams should be allowed in data, nothing resolveable here.

  20. modified the milestones: invalid, backlog on May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions