Skip to content

groupedMapReduce and optional base #945

Closed

Description

@neumino

One table "posts" in the database "blog" with a single document

[
    {
        "num_comments":92,
        "id":"bb1b6983-0f40-451e-b0e7-7f52dc4d3aa1",
        "category":"category3"
    }
]

Query that fails

r.db("blog").table("posts").groupedMapReduce(
  function(post) { return post("category") },
  function(post) { return post("num_comments") },
  function(left, right) { return left.add(right)},
  {category:"none", num_comments:0}
  )

With the backtrace

RqlRuntimeError: Expected type NUMBER but found OBJECT. in:
r.db("blog").table("posts").groupedMapReduce(function(var_112) { return var_112("category"); }, function(var_113) { return var_113("num_comments"); }, function(var_114) { return var_114.add(var_115); }, {base: {category: "none", num_comments: 2}})
                                                                                                                                                                                  ^^^^^^^^^^^^^^^^^^^^    

Removing the optional base works fine, replacing with 0 works fine too, replacing it with 1 provides a driver error

RqlDriverError: Expected 3 argument(s) but found 4.

Not sure how important it is since we are going to get rid of the base.
@mlucy could you comment on this?

Activity

  1. mlucy commented on Jun 5, 2013

    @mlucy
    Member

    @wmrowan -- how do you specify the optional base in the JS client?

    I think we should let this lie since we're going to remove the optional base soon.

  2. wmrowan commented on Jun 5, 2013

    @wmrowan
    Contributor

    The base is taken as an optional 4th parameter. It's then passed as the 'base' field of the optional arguments dict. The weird error checking here comes from the fact that it's using aropt to check the number of fields. The simple heuristic "is the 4th value an object?" is used to decided if this is an options dict or not which is why we get different results when it's a number. The distinction between 0 and 1 exists because 0 is falsy (and apparently the ? operator is CoffeeScript doesn't work as advertised, -1 one more for coffeescript).

    The type error though is coming from the server. Why doesn't the server accept an object value as a base argument?

    Fortunately, we don't have to worry about any of this because we're getting rid of the optional base argument. Michel was testing this for the docs and I think the most reasonable way forwards is to just remove all reference to the base argument from the docs now even if it's still technically in there.

  3. mlucy commented on Jun 5, 2013

    @mlucy
    Member

    I concur; in GMR it was superfluous even before we had default.

  4. coffeemug commented on Feb 17, 2014

    @coffeemug
    Contributor

    @mlucy -- should we close this now that #888 is closed? I don't see anything else we can realistically do here.

  5. modified the milestones: duplicate, backlog on Feb 18, 2014
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