Skip to content

Revisit GROUPED_DATA format in js #2032

Closed

Description

@mlucy

I'm sort of unhappy with the current format because:

  • It makes people think they're dealing with an array.
  • It makes it hard to explain what groups_to_array does.

Activity

  1. added this to the 1.12 milestone on Feb 27, 2014
  2. coffeemug commented on Feb 27, 2014

    @coffeemug
    Contributor

    Also a note that @neumino is really unhappy with the state of affairs too (though for different reasons, I think).

  3. mlucy commented on Feb 27, 2014

    @mlucy
    MemberAuthor

    @neumino -- are you unhappy with the format in JS, or with the fact that the formats are different in the different drivers?

  4. neumino commented on Feb 27, 2014

    @neumino
    Member

    @mlucy -- with the fact that the formats are different in the different drivers.

    Users often try stuff in the data explorer, then translate their queries in python/ruby/go/etc. And basically with group, they won't be able to.
    It's a little worse since this is useful when you build complicated queries, like with group for example.

    We should have by default the same values in all three drivers. We can then have flags/options to change the format if the user want.

  5. Tryneus commented on Feb 27, 2014

    @Tryneus
    Member

    Ok, I'm leaning towards defining an object for the Javascript and Python drivers that supports iteration and getting a given group from the results. I believe this will satisfy a vast majority of the use cases, and allows us to make a wrap around the limitations of dicts/Objects in py and js (specifically that we cannot have dicts/Objects as keys).

    I'm working on a Javascript implementation now of a GroupedData object that implements hasNext, next, each, toArray, and get, so people can play around with it and see how it feels. The python version should be much easier to do.

  6. neumino commented on Feb 27, 2014

    @neumino
    Member

    Isn't the GroupedData object just a cursor then?

    What does the user get back with groupedData.next?

  7. Tryneus commented on Feb 27, 2014

    @Tryneus
    Member

    The idea is the same as the cursor, but the implementation is a little different since we're wrapping the GROUPED_DATA format. next could either return [<group>, <reduction>] or {group:<group>,reduction:<reduction>}, probably the latter since that is what we went with earlier.

  8. mlucy commented on Feb 27, 2014

    @mlucy
    MemberAuthor

    I think we should mimic Ruby's object iteration interface; you should pass a callback to next that takes two arguments, and that callback should be called with key, value pairs.

  9. neumino commented on Feb 27, 2014

    @neumino
    Member

    After a group command and as long you haven't call ungroup, all the methods you call are going to be executed on each group.
    It's as simple as that.

    I don't understand why we need to create a new type in the driver.

  10. mlucy commented on Feb 27, 2014

    @mlucy
    MemberAuthor

    @neumino -- the problem is that people call tbl.group('a').count(), and they get back [{group: ..., reduction: ...}, ...], and they're like "OK, I've got an array, I'll order that array by the reduction..." -- then they run tbl.group('a').count().orderBy('reduction'), and it doesn't do what they expect.

    Then maybe they go read the docs, they find out about this "ungroup", and they're like OK, and they run tbl.group('a').count().ungroup(), and they get back...the exact same thing they got before ([{group: ..., reduction: ...}, ...]). And they're like "what the fuck does ungroup do?". The idea that the type you get on the client corresponds the the type you get on the server if you call ungroup is really hard to explain.

  11. AtnNn commented on Feb 27, 2014

    @AtnNn
    Member

    Do avoid the confusion, can we not send grouped results back to the clients and force them to use ungroup? We could also have ungroup_as_object() or ungroup(object=true).

  12. mlucy commented on Feb 27, 2014

    @mlucy
    MemberAuthor

    You mean just return the pseudotype in JS? I think that would be better than what we have now, but I'd like to see what the interface @Tryneus is working on feels like in practice.

  13. AtnNn commented on Feb 27, 2014

    @AtnNn
    Member

    @mlucy no, I mean that .run() on a grouped_stream or grouped_datums would be an error.

  14. mlucy commented on Feb 27, 2014

    @mlucy
    MemberAuthor

    @AtnNn -- Forcing people to always call ungroup at the end seems like it would get super annoying. (Also, I think the object format of GROUPED_DATA is what you actually want to get back in Ruby.)

    Although, maybe my first instincts on this are wrong. @coffeemug, what do you think?

  15. neumino commented on Feb 27, 2014

    @neumino
    Member

    They are going to run

    r.table("foo").group('a').count().run(connection, function(err, cursor) {
        if (err) throw err;
        cursor.toArray(function(err, result) {
            console.log(JSON.stringify(result, null, 2))
        })
    })
    

    And they will never know that they have a grouped_data object. Returning a new type of object doesn't solve the problem.
    Node.js users don't use the shell as python users can.

    I also don't see what's wrong with the explanation of group/ungroup I gave in my previous comment.

    We shouldn't worry about the driver not always matching the type of a result with the type in the server.

    Having to deal with array and cursor is already confusing -- and if someone thinks it's not, and wants to reopen this debate, I would be happy to go through my logs to show concrete example of confused users.
    Adding a grouped_data is exactly the same thing (maybe worst).

    If we keep matching the driver and the server, we are going to end up adding a new type of object for numbers since JavaScript numbers are just 32 bits double.

  16. mlucy commented on Feb 28, 2014

    @mlucy
    MemberAuthor

    @neumino -- I can't speak for all users, but it is SUPER confusing in the data explorer. Saying "the behavior is well-defined and can be explained" doesn't really matter when the first-touch experience of using it is confusing and complicated. Having two types which don't behave the same way but which are displayed exactly the same way in the data explorer is too confusing to ship with, even if we can explain to users why it is that way.

  17. mlucy commented on Feb 28, 2014

    @mlucy
    MemberAuthor

    Also, I think the iteration would be something like:

    tbl.group('a').count().run(conn, function(err, groups) {
      if (err) throw err;
      groups.forEach(function(group, reduction) {
        console.log(...)
      })
    })
  18. mlucy commented on Feb 28, 2014

    @mlucy
    MemberAuthor

    (Also, to clarify what I mean by confusing, Slava's first intuition was that he could call orderBy('reduction') on the output of .group('a').count(), and he helped design the feature. It would have been my first intuition too if I hadn't implemented the server behavior.)

  19. neumino commented on Feb 28, 2014

    @neumino
    Member

    We can just improve the error message, in case an error (maybe just some of them) is thrown in a group_data/group_streams, we can suggest that maybe they want to ungroup before.

    I still think that adding a new type is not the solution here and is just going to end up as a burden for our users.

    Note: The data explorer already presents cursor and arrays the same way.

  20. Tryneus commented on Feb 28, 2014

    @Tryneus
    Member

    I think the biggest benefit of adding a wrapper class is that we can allow random access of the results, which might be a pain for users to do themselves. Avoiding confusing users is nice, but we should focus on what makes a simple and usable interface. At this point, I'm not convinced the wrapper classes are a good idea, if we just return [{group:<group>,reduction:<reduction>}...], and let users handle it from there, I think that is enough.

  21. neumino commented on Feb 28, 2014

    @neumino
    Member

    We can return an ArrayResult then.

  22. coffeemug commented on Feb 28, 2014

    @coffeemug
    Contributor

    I very strongly disagree with @AtnNn's proposal. Forcing people to call ungroup to get the data back is extremely annoying. I think doing that would cut the pleasantness of this feature in half.

    I'm also very strongly opposed to representing GROUP_DATA in JS via the same object that the user would get by calling ungroup. That's extremely confusing.

    Instead of building a custom wrapper, why don't we just construct a native JavaScript object (like we do in Ruby)?

  23. coffeemug commented on Feb 28, 2014

    @coffeemug
    Contributor

    Err, actually I'm opposed to the last part (constructing a native JS object), all the automagical conversion to strings is just terrible.

    So it's between a custom object or an array of pairs (an array of arrays, basically). I think an array of pairs is easiest: [['nyc', 2], ['sf', 1]]. If people want a proper {group: ..., reduction: ...} they can call ungroup.

    How about that?

  24. mlucy commented on Feb 28, 2014

    @mlucy
    MemberAuthor

    @coffeemug -- an array of pairs solves half the confusion ("the output is the same whether or not I call ungroup", but not "I'm getting back an array but I can't chain functions on the end like I expect"). If we have to do something like this, we should return something that doesn't look like another type in our type system (e.g. we could return the raw psuedotype).

    @neumino -- we can't just solve this with a better error message because sometimes we just do the wrong thing rather than causing an error. For example, if the user writes tbl.group('a').min('a').pluck('reduction'), they probably expect to get back an array like [{reduction: ...}, ...], but instead they get back [{group: ..., reduction: {}}, ...].

    @Tryneus -- "confusing" and "simple and usable" or not orthogonal. In this case, I think confusion is our biggest usability problem.

  25. coffeemug commented on Feb 28, 2014

    @coffeemug
    Contributor

    an array of pairs solves half the confusion ("the output is the same whether or not I call ungroup", but not "I'm getting back an array but I can't chain functions on the end like I expect"

    I see. I think the latter is a smaller problem, though. Also, this will be a problem with the way we present the results in the data explorer.

    Let me know if you need me to rally people together in a room and such (we do need to arrive at a good solution, as this is stretching).

  26. Tryneus commented on Mar 4, 2014

    @Tryneus
    Member

    Regarding the changes we discussed to the returned dict object in python, it is actually impossible to modify those attributes on a dict, we would need a new type.

  27. coffeemug commented on Mar 4, 2014

    @coffeemug
    Contributor

    Ok, closing this issue.

    I've opened #2054 for an infobox in the data explorer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions